多个重写规则与变量在.htaccess


Multiple Rewrite Rules with variables in .htaccess

我正在尝试使用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

你的规则是这样的:

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]

。处理2个斜杠规则之前重写为home.php