0

我写了一个简单的 mod 重写脚本来website.com/index.php?var1=1&var2=2&var3=3变成website.com/index/1/2/3. 由于某种原因它不起作用,任何想法为什么?

#RewriteRule ^$ index.php [QSA]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1\.php [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [QSA]

RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ comments.php?var1=$1&var2=$2&var3=$3
4

2 回答 2

1
  • 第一条规则重写index/1/2/3index/1/2/3.php
  • 然后第二条规则将其重写为index.php/index/1/2/3.php
  • 最后最后一条规则不匹配。

如果要重写website.com/index.php?var1=1&var2=2&var3=3website.com/index/1/2/3,则必须捕获查询字符串参数RewriteCond并将它们插入到RewriteRule

RewriteEngine on
RewriteCond %{QUERY_STRING} var1=(.*?)&var2=(.*?)&var3=(.*?)
RewriteRule ^index.php$ /index/%1/%2/%3 [L]

如果您想重定向而不是内部重写,即在浏览器中显示新 URL,请[R,L]用作 RewriteRule 标志

RewriteRule ^index.php$ /index/%1/%2/%3 [R,L]
于 2013-03-30T01:32:16.867 回答
0

It looks like the rewrite on line 6 will catch that and send it to index.php. It's hard to tell not knowing what things are files and directories, but I would guess that it isn't. If you have access to the httpd.conf you can turn up the rewrite logging, set

RewriteLogLevel 8

And it will log far more information than you need to debug this. On newer versions of apache the setting is set with LogLevel e.g..

LogLevel alert rewrite:trace8

which may be allowed in vhosts or htaccess so look it up in your version's docs.

Don't leave this on as it will seriously impact performance.

于 2013-03-29T23:08:43.097 回答