【发布时间】:2013-01-19 12:35:02
【问题描述】:
我在 .htaccess 中有以下代码
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)(/([^/]+))?(/(edit)+)(/([^/]+))?/?$ edit.php?secret=Y7qD7&category=$1&slug=$3&edit=$5&part=$7 [L]
RewriteRule ^([^/]+)(/([^/]+))?/?$ content.php?category=$1&slug=$3 [L]
RewriteRule ^(/)?$ content.php [L]
我期望达到的是
http://example.com/test/test1/edit/part to edit.php?category=test&slug=test1&edit=edit&part=part
http://example.com/test/edit/part to edit.php?category=test&slug=&edit=edit&part=part
(以上重写按预期工作)
`http://example.com/test/test/` to `content.php?category=test&slug=test`
`http://example.com/test/` to `content.php?category=test&slug=`
(请注意,以上2个url中没有“/edit/”和“/part/”)
对于以上两个重写,第一个工作正常,但第二个没有按预期工作。最后一个被重写为 content.php?category=content.php&slug= 这是不正确的。
尾随斜杠也不应该对重写产生影响。
有人可以告诉我我在这里做错了什么吗?
【问题讨论】:
标签: .htaccess mod-rewrite url-rewriting rewrite