我正在进行重写,但它不适用于我。我已经浪费了我2天的时间。你的帮助将是值得赞赏的。
RewriteRule test/(.*)/(.*)/$ /include/test?$1=$2 //not working
RewriteRule test/(\w+)/(\w+)/$ /include/test?$1=$2 //not working
RewriteRule ^test/(\w+)/(\w+)/$ /include/test?$1=$2 //not working
RewriteRule .* include/test.php?id=123 //working
尝试PHP代码
echo $_SERVER['PHP_SELF'] // include/test.php/id/1234 (after rewrite)
// expecting : /include/test.php?id=1234
请求用户网址:
http://www.example.com/include/test/id/1234
重新:
http://www.example.com/include/test.php?id=1234
可能出现的问题:
主要问题:
未获得$_GET
值
Test.php
<?php
ini_set("display_errors",1);
echo $_GET['id'];
echo $_SERVER['PHP_SELF'].'<br/>';
echo $_SERVER['PATH_INFO'];
?>
请求
http://www.example.com//include/test/id/1234
输出:
/include/test.php/id/1234
/id/1234
答案 0 :(得分:1)
规则看起来没问题,我能看到的唯一问题是测试URI的尾部斜杠:http://www.example.com/include/test/id/1234
请尝试:
RewriteRule test/(.*)/(.*)/?$ /include/test.php?$1=$2
RewriteRule test/(\w+)/(\w+)/?$ /include/test.php?$1=$2
RewriteRule ^test/(\w+)/(\w+)/?$ /include/test.php?$1=$2
此外,您不需要上述所有三个规则。第一个应该涵盖第一个和第二个。所以,你可以删除第二个。假设这些是你不同的测试,我就把它放在那里。
更新:
向目标URI添加.php
扩展名,即将/include/test?$1=$2
替换为/include/test.php?$1=$2