[英]Unusual behaviour of Htaccess URL-Rewrite
I'm using jQuery Autocomplete (fetching values from a database) and displaying results to the user from the database. 我正在使用jQuery Autocomplete(从数据库中获取值)并从数据库向用户显示结果。 The search results are clickable and when they click, they are sent to a page called product_display.php with id as the request parameter.
搜索结果是可点击的,当他们点击时,他们会被发送到名为product_display.php的页面,其中id为请求参数。 Therefore example, it would be something like this :- product_display.php?id=2
因此,例如,它将是这样的: - product_display.php?id = 2
On the product_display.php page, there are 3 radio buttons and 3 forms (one for each radio button, the forms open dynamically upon radio select). 在product_display.php页面上,有3个单选按钮和3个表单(每个单选按钮一个,表单通过无线电选择动态打开)。 Each form has a separate submit button.
每个表单都有一个单独的提交按钮。 Upon hitting submit, it goes to a different page and the value of a hidden variable named cond is printed.
点击提交后,它会转到另一个页面,并打印一个名为cond的隐藏变量的值。
Everything was working fine until I introduced a Url-Rewrite in my htaccess file, to conver *product_display.php?id=2* to /products/2 一切正常,直到我在我的htaccess文件中引入了Url-Rewrite,转换为* product_display.php?id = 2 *到/ products / 2
When this url-rewrite came into work, the results were not good. 当这个url-rewrite开始工作时,结果并不好。 As soon as I click the submit button for any form pertaining to any radio button, it again displays the options which were on the product_display page (but header shows different page).
只要我点击任何与任何单选按钮相关的表单的提交按钮,它就会再次显示product_display页面上的选项(但标题显示不同的页面)。 How can this be fixed.
如何解决这个问题。
jQuery Auto Complete. jQuery自动完成。
<script>
$(function() {
function log( message ) {
$( "<div>" ).text( message ).prependTo( "#log" );
$( "#log" ).scrollTop( 0 );
}
$( "#birds" ).autocomplete({
source: "search.php",
minLength: 2,
select: function( event, ui ) {
log( ui.item ? "Selected: " + ui.item.value + " aka " + ui.item.label :
"Nothing selected, input was " + this.actor );
window.location.href = './products/' + ui.item.value;
//window.location.href = 'product_display.php?id=' + ui.item.value;
// document.testForm.action = "pretravel.php?id="+ui.item.value;
//document.testForm.submit();
}
});
});
products_display.php products_display.php
<div id="credit-card">
<section id="content">
<input type="radio" id="radio1" name="radios" value="radio1" checked>
<label for="radio1">Working</label>
<input type="radio" id="radio2" name="radios" value="radio2">
<label for="radio2">Working - Damaged</label>
<input type="radio" id="radio3" name="radios" value="radio3">
<label for="radio3">Not Working</label>
<form action="offer_show.php" method="post" id="working">
<input type="hidden" name="cond" value="working" id="cond">
<input type="submit" name="submit">
</form>
<form action="offer_show.php" method="post" id="workingdamaged">
DEbit Card payment here
<input type="hidden" name="cond" value="workingdamaged" id="cond">
<input type="submit" name="submit">
</form>
<form action="offer_show.php" method="post" id="nonworking">
<input type="hidden" name="cond" value="damaged" id="cond">
<input type="submit" name="submit">
</form>
</section>
</div>
</body>
<script type="text/javascript">
var radios = document.getElementsByName("radios");
var working = document.getElementById("working");
var workingdamaged = document.getElementById("workingdamaged");
var nonworking = document.getElementById("nonworking");
working.style.display = 'block'; // show
workingdamaged.style.display = 'none';
nonworking.style.display = 'none';// hide
for(var i = 0; i < radios.length; i++) {
radios[i].onclick = function() {
var val = this.value;
if(val == 'radio1')
{
working.style.display = 'block';
workingdamaged.style.display = 'none';
nonworking.style.display = 'none';
}
else if(val == 'radio2')
{
working.style.display = 'none';
workingdamaged.style.display = 'block';
nonworking.style.display = 'none';
}
else if(val == 'radio3')
{
working.style.display = 'none';
workingdamaged.style.display = 'none';
nonworking.style.display = 'block';
}
}
}
</script>
htaccess htaccess的
RewriteRule ^products/(.+)$ product_display.php?id=$1 [L,QSA]
offer_show.php (the page which opens upon clicking submit) offer_show.php(单击提交时打开的页面)
<?php
echo $_REQUEST['cond'];
?>
It's probably a relative/absolute URL thing. 它可能是一个相对/绝对URL的东西。 Your form has this as its action:
您的表单将此作为其操作:
action="offer_show.php"
which means when you go to: /products/123
, the forum gets submitted to /products/offer_show.php
, which gets rewritten to /product_display.php?id=offer_show.php
. 这意味着当你去:
/products/123
,论坛会被提交到/products/offer_show.php
,后者会被重写为/product_display.php?id=offer_show.php
。
Try changing the form's action to an absolute URL: 尝试将表单的操作更改为绝对URL:
action="/offer_show.php"
And you may also want to add 而且您可能还想添加
<base href="/" />
to your page's header. 到您页面的标题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.