" / username"的规则在HTACCESS中

时间:2015-03-08 11:05:19

标签: php apache .htaccess mod-rewrite

我想在RewriteRule中实施.htaccess以启用以下网址结构:

http://example.com/([a-zA-Z\.]*) -> user.php?username=$1

我试过这样:

RewriteRule ^([a-zA-Z\.]*)$ user.php?username=$1 [L,QSA]

如果我转到localhost/victorbarbu,它会重定向到user.php?username=victorbarbu,但如果我转到storage/,它仍会转到user.php。我该怎么做才能避免这种重定向?

这是我目前的.htaccess

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .*[^/]$ $0/ [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteCond %{THE_REQUEST} \ /+subdir/
RewriteRule ^ - [L]

1 个答案:

答案 0 :(得分:1)

试试这个:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php !-f
RewriteRule ^([a-zA-Z.]*)$ user.php?username=$1 [L,QSA]