我在找到两个重写规则的正确reg-exp时遇到问题。我正在检查文件名是不是有效的目录,文件或链接,然后继续执行两个重写规则(如果是这种情况)。他们分开工作,但如果他们都打开了,就会发生冲突。
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ([^/][a-zA-Z]+)/([0-9]+)$ /post.php?no=$2
RewriteRule ([^/][a-zA-Z]+)$ /profile.php?name=$1
所需的网址是:
用户帖子:... com / username / 81
用户个人资料:... com / username
任何建议都将非常感谢,
感谢
答案 0 :(得分:1)
RewriteCond
仅适用于下一个RewriteRule
,但您有第二个RewriteCond
,但没有RewriteCond
。使用此代码:
RewriteEngine On
# If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
# If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteRule ([^/][a-zA-Z]+)/([0-9]+)$ /post.php?no=$2 [L,QSA]
RewriteRule ([^/][a-zA-Z]+)$ /profile.php?name=$1 [L,QSA]