我的规则是从http://localhost/username
重定向到http://localhost/profile_redirect.php?user=username
htaccess规则是
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)/?$ $1.php [L]
# when user name != directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)/?$ profile_redirect.php?user=$1 [L,QSA]
# when user name == directory
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^([^.]+)/$ profile_redirect.php?user=$1 [L,QSA]
是否可以为此规则设置例外情况?例如,我有一个包含网址http://localhost/members
的网页,因此在使用该网址时,由于.htaccess规则,它会重定向到http://localhost/profile_redirect.php?user=members
,这不应该发生。
我只有3个这样的例外。
答案 0 :(得分:2)
你的规则如下:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)/?$ $1.php [L]
# ignore these paths for further rewriting
RewriteRule ^(members|exception1|exception2)(/|$) - [NC,L]
# when user name != directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)/?$ profile_redirect.php?user=$1 [L,QSA]
# when user name == directory
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^([^.]+)/$ profile_redirect.php?user=$1 [L,QSA]