简体   繁体   中英

URL rewrite rules with Apache

I have a .htaccess file like this:

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]

I can use my url like this

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

But some rules does not work. For example:

www.mysite.com/p/timeline

There is a problem with url which include mysite.com/p/..

Anyone can help me?

You should first parse the rules for p/timeline and p/notification . The ordering of your rules is also important.

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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