【发布时间】:2012-09-06 09:31:30
【问题描述】:
鉴于我的网站中有以下网址:http://localhost/test/example.php?a=1&b=2
如何在我的 .htaccess 文件中指定重定向规则,以便当我在浏览器中输入以下内容时调用此 URL:http://localhost/test/example/1.html
换句话说,如果用户输入url:http://localhost/test/example/1.html,他应该显示的页面:http://localhost/test/example.php?a=1&b=2
我在我的 .htaccess 文件中尝试了以下 mod_rewrite 代码,但它不起作用:
RewriteRule ^/([^/]+).html /example.php?a=$1&b=$2 [QSA]
这是我的 .htaccess 文件中的代码:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([^/]+)/([^/]+)/? /example.php?a=$1&b=$2 [QSA]
注意:我使用的是 WAMP2.0、Apache 2.2.6 和 PHP 5.2.5
【问题讨论】:
-
第二个参数
b在重写后的 URL 中在哪里? -
我不需要重写后的url中的第二个参数..我只需要第一个参数,然后是html扩展名。
-
你打开重写引擎了吗?
-
是的,我已经编辑了我的问题,在我的 .htaccess 文件中添加了代码
-
把这个放在你的example.php中帮助你调试
<?php echo $_GET['a'].$_GET['b']; ?>
标签: php .htaccess mod-rewrite url-rewriting