2017-09-05 79 views
1

当我尝试这样做htaccess的:htaccess的清洁网址的个人资料页

RewriteEngine on 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 
ErrorDocument 404 /includes/errors/404.php 
ErrorDocument 403 /includes/errors/403.php 
RewriteRule ^profile/([^/]+)$ /profile?user=$1 

它的工作原理,但我读的名字是错的。 当我做例如http://localhost/profile/Andre我得到Andre.php作为用户,而不是安德烈。 有人知道如何解决这个问题吗?

回答

2

发生这种情况是因为您根据自己的第一条规则进行了重写,并且因为它被设置为最后一次,所以会发生这种情况。尝试移动上方的简档规则:

RewriteEngine on 
RewriteRule ^profile/([^/]+)$ /profile?user=$1 [NC,L] 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 
ErrorDocument 404 /includes/errors/404.php 
ErrorDocument 403 /includes/errors/403.php 

我还添加[NC,L]来标记规则为ñöÇ ase和大号 AST