我有一个.htaccess文件,我在其中重写规则
RewriteRule ^([0-9A-Za-z]+)$ profile.php?username=$1
使myproject.com/profile.php?username=iamuser
成为myproject.com/iamuser
但是如果我想去一个文件夹,例如“images”,当我写myproject.com/images
时,它会在profile.php上保留为'images'作为用户名
请帮忙。感谢
答案 0 :(得分:1)
You should use RewriteCond
to check if the request URI belongs to any existing files / directories.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9A-Za-z]+)$ profile.php?username=$1 [QSA,L]
-d
tests whether it exists and is a directory. -f
tests whether it exists and is a file. The QSA
flag appends the query string if any of the original request. The L
flag makes it the last rule to process. No other rules behind are processed if this rule matches.