繁体   English   中英

.htaccess两个重写规则之间的冲突

[英].htaccess conflict between two rewrite rule

在我的网站中,两个重写规则相互冲突,我为我的用户提供了url,例如http://twekr.com/sam,并且我的所有网站页面都以http://twekr.com/login的形式打开

现在这里是htaccess文件规则

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

RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?user=$1

现在只有此规则有效,因为它先加载=

RewriteCond %{REQUEST_FILENAME} !-d

如果我把配置文件重写规则放在上面

RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?user=$1 (then this works)

而且这不

RewriteCond %{REQUEST_FILENAME} !-d (does not work)

htaccess规则有什么问题?

在添加.php扩展名之前,您应检查是否存在.php文件:

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

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/?$ profile.php?user=$1 [L,QSA]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM