使用Apache重写URL规则
我有一个.htaccess文件,如下所示:使用Apache重写URL规则,apache,.htaccess,mod-rewrite,url-rewriting,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 notif
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]
我可以像这样使用我的url
www.mysite.com/username
or
www.mysite.com/username/photos
但有些规则不起作用。例如:
www.mysite.com/p/timeline
包含mysite.com/p/的url有问题。
有人能帮我吗?您应该首先解析
p/时间线
和p/通知
的规则。规则的顺序也很重要
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]