Apache

时间:2015-04-28 23:17:44

标签: apache .htaccess mod-rewrite url-rewriting

我有一个像这样的.htaccess文件:

RewriteEngine On

RewriteRule ^([\w-]+)/([\w-]+)/?$ profile.php?username=$1&w=$2 [QSA,L]
RewriteRule ^([\w-]+)/?$ profile.php?username=$1 [QSA,L]
RewriteRule ^p/timeline timeline.php [NC,L]
RewriteRule ^p/notifications notifications.php [NC,L]

我可以像这样使用我的网址

www.mysite.com/username
or
www.mysite.com/username/photos

但有些规则不起作用。例如:

www.mysite.com/p/timeline

网址存在问题,包括 mysite.com/p /..

任何人都可以帮助我?

1 个答案:

答案 0 :(得分:2)

您应首先解析p/timelinep/notification的规则。规则的排序也很重要。

RewriteEngine On

RewriteRule ^p/(notifications|timeline) $1.php [NC,L]
RewriteRule ^([\w-]+)/([\w-]+)/?$ profile.php?username=$1&w=$2 [QSA,L]
RewriteRule ^([\w-]+)/?$ profile.php?username=$1 [QSA,L]