【发布时间】:2015-07-28 17:46:02
【问题描述】:
这是我的重写规则:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,QSA,L]
RewriteRule ^index\.(html?|php)$ http://%{HTTP_HOST}/ [R=301,QSA,L]
RewriteRule ^info/db$ info/db/index.php?kid=7 [L]
RewriteRule ^info/db/general$ info/db/general.php?kid=15 [L]
当我输入 URL www.mypage.com/info/db 时,无法识别查询参数($_GET 不包含任何内容)。
但是,当我单击站点中指向同一页面的链接时,会识别查询字符串,并且可以通过 $_GET 访问它。但是浏览器窗口中的 URL 显示为www.mypage.com/info/db/?kid=7。
为什么会这样?我哪里错了?
编辑
测试.htaccess
Options -MultiViews
RewriteEngine On
RewriteRule ^abc_([0-9]+)$ abc.php?kid=$1 [NC, L]
RewriteRule ^folder/abc_([0-9]+)$ folder/abc.php?kid=$1 [NC, L]
RewriteRule ^folder$ folder/index.php?kid=2 [NC,L]
我调用 u.php,其中包含:
<a href="abc_123">KLICK</a>
一切正常。
我点击链接,在 URL 栏中显示:
http://localhost/mystuff/abc_123
123 会在页面上回显,因为它应该:
<?php
echo $_GET["kid"];
?>
当我直接输入http://localhost/mystuff/abc_123 时,它也可以工作。
当我直接输入http://localhost/mystuff/folder/abc_123 时,123 应该会显示在页面上。
当我调用http://localhost/mystuff/folder 时,查询字符串按原样传递并在页面上回显,但 URL 栏显示:
http://localhost/mystuff/folder/?kid=2
重写规则是我现在在那个 .htaccess 中唯一的东西。
【问题讨论】:
-
我无法重现您的问题。一切正常。查询通过。要在浏览器中看到它,请写
[L,R]
标签: php .htaccess mod-rewrite