我在为两个重写规则找到正确的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 /用户名/ 81
用户个人资料:... com /用户名
任何建议将不胜感激,
谢谢
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]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句