【发布时间】:2020-11-19 10:15:24
【问题描述】:
今天我开始为 php 脚本重写我的 mod。 关于设置的一些话
我使用子域,例如test.testsystem.com 指向 root/test/ 所以我的 PHP 脚本有多个 GET 参数,如下所示:
1) https://test.testsystem.com/index.php?a=foo
2) https://test.testsystem.com/index.php?a=foo&v=bar
3) https://test.testsystem.com/index.php?a=foo&c=testcode
所以有了 mod rewrite 我想拥有
1) https://test.testsystem.com/foo
2) https://test.testsystem.com/foo/bar
3) https://test.testsystem.com/foo/c/testcode
我现在拥有的是
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /test/
RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ index.php?a=$1 [QSA]
RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ index.php?a=$1&v=$2 [QSA]
对于前两个 URL。现在它不再出现错误 500 但问题是我的 php 脚本中没有任何 GET 参数。
也许有人可以在这里为我提供一个可行的解决方案。
问候
【问题讨论】:
-
您的规则都要求请求的 URL 路径以两个字母开头,后跟一个斜杠。您提到的三个输入 URL 示例均不满足该条件。
-
并且尝试在两个连续的规则中匹配 exact same 模式也没有什么意义。
-
是的,你是对的,我将其更改为 RewriteRule ^(.*[^/])$ index.php?a=$1 [QSA] 作为第一条规则,但它也不起作用
-
它是否适用于您的第一个 URI
RewriteRule ^foo$ index.php?a=foo [L]在地址栏中输入 /foo 只是为了查看您的 php 脚本中是否有foo变量。 -
我用test.testsystem.com/foo 对其进行了测试,并在index.php 中使用了以下内容:
$request = array_merge($_GET, $_POST); print_r($request);我得到的只是array()....所以数组中没有条目
标签: php apache .htaccess mod-rewrite