[英].htaccess doesn't redirect properly
我有这个自动完成脚本从jquery。 当用户单击特定结果时,它将从数据库中获取详细信息,然后显示给用户。他进入页面:-page.php?id =(通过autcomplete中的fetch接收到的id)。
我有一个.htaccess重定向,它必须像这样工作。 假设id为2,则它将自动重定向到products / 2 。 但是由于某种原因,它似乎没有用。
这是自动完成功能:-
<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
RewriteRule ^products/(.+)$ product_display.php?id=$1 [L,QSA]
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'];
?>
欢迎任何建议。
这是您的JavaScript错字,请更改此
window.location.href = 'product_display.php?id=' + ui.item.value;
至
window.location.href = './product_display.php?id=' + ui.item.value;
然后只有完整的URL。 [更新]您的重写规则是这样的
RewriteRule ^products/(.+)$ product_display.php?id=$1 [L,QSA]
所以你的网址一定是这样
// sample url http://example.com/products/{id}
//then code must be
window.location.href = './products/' + ui.item.value;
[更新]尝试使用的mysqli替代的MySQL连接好安全数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.