我正在重写,但它对我不起作用。我已经为此浪费了两天时间。您的帮助将不胜感激。
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
用户url请求:
http://www.example.com/include/test/id/1234
回放到:
http://www.example.com/include/test.php?id=1234
可能的问题:
- 不获取$1、$2的值
- 不匹配模式(尽管模式是当前的)
- 不重定向到替代品(内部)
主要问题:
未获取$_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
规则看起来不错,我能看到的唯一问题是测试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
此外,您不需要以上三条规则。第一个应该涵盖第一个和第二个。所以,你可以去掉第二个。我只是把它放在那里,假设这些是你不同的测试。
更新:
将.php
扩展添加到目标URI,即用/include/test.php?$1=$2
替换/include/test?$1=$2