我正在尝试使用htaccess重写规则。我需要
http://www.sitename.com/variable/upload.php
映射到
http://sitename.com/upload.php?slug=variable
http://www.sitename.com/variable/gallery.php
映射到
http://sitename.com/gallery.php?slug=variable
http://www.sitename.com/variable/
映射到
http://sitename.com/home.php?slug=variable
对于第三部分,我有:
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+) home.php?slug=$1 [L]
但现在http://www.sitename.com/variable/upload.php
也会映射到http://sitename.com/home.php?slug=variable
我该怎么做?
答案 0 :(得分:1)
你的规则如下:
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ $2?slug=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ home.php?slug=$1 [L,QSA]
即。在重写为home.php