[英].htaccess doesn't redirect properly
I have this autocomplete script fron jquery. 我有这个自动完成脚本从jquery。 It fetches details from a database and then displays to the user, when the user clicks on a particular result..he is taken to a page :- page.php?id=(id received via fetch in autcomplete). 当用户单击特定结果时,它将从数据库中获取详细信息,然后显示给用户。他进入页面:-page.php?id =(通过autcomplete中的fetch接收到的id)。
I have a .htaccess redirect which had to work like this. 我有一个.htaccess重定向,它必须像这样工作。 Suppose the id is 2, then it would automatically redirect to products/2 . 假设id为2,则它将自动重定向到products / 2 。 But for some reason, it doesn't seems to be working. 但是由于某种原因,它似乎没有用。
Here is the autocomplete :- 这是自动完成功能:-
<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 = 'product_display.php?id=' + ui.item.value;
// document.testForm.action = "pretravel.php?id="+ui.item.value;
//document.testForm.submit();
}
});
});
</script>
.htaccess 的.htaccess
RewriteRule ^products/(.+)$ product_display.php?id=$1 [L,QSA]
product_display.php page product_display.php页面
<?php
include 'dbconnector.php';
$id=$_GET['id'];
$id=htmlspecialchars($id);
$query = "SELECT productname from products where productid = '" . $id . "' order by productname";
$result=mysql_query($query,$db) or die (mysql_error($db));
$row=mysql_fetch_assoc($result);
echo $row['productname'];
?>
Any suggestions are welcome. 欢迎任何建议。
It is your javascript typo, Change this 这是您的JavaScript错字,请更改此
window.location.href = 'product_display.php?id=' + ui.item.value;
To 至
window.location.href = './product_display.php?id=' + ui.item.value;
Then only the complete url comes. 然后只有完整的URL。 [Update] Your rewrite rule is like this [更新]您的重写规则是这样的
RewriteRule ^products/(.+)$ product_display.php?id=$1 [L,QSA]
So you url must come like this 所以你的网址一定是这样
// sample url http://example.com/products/{id}
//then code must be
window.location.href = './products/' + ui.item.value;
[update] Try using mysqli instead of mysql to connect database for good security. [更新]尝试使用的mysqli替代的MySQL连接好安全数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.