简体   繁体   中英

Different htaccess directory and subdirectory redirect

I am trying to have clean urls on my site and here is the mapping I'm trying to achieve:

  1. mysite.tld/directory/ is going to > mysite.tld/page.php?q=directory
  2. mysite.tld/tags/directory/ is going to > mysite.tld/tag.php?q=directory

I have made an htaccess file at the root of my site wiht the folling code:

RewriteEngine On
RewriteRule ^([^\/]+)\/?$ pages.php?q=$1 [L,QSA]
RewriteRule ^tags/([^/d]+)/?$ tags.php?q=$1 [L,QSA]

For some reason, the tag redirect works but is then "eaten" by the other rule of redirection. Not sure what to do to prevent second rule from doing this.

Answer is as follow:

RewriteEngine On
RewriteRule ^tags/([^/d]+)\/? /tags.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_URI} !/tags
RewriteRule (.*) pages.php?q=$1 [L,QSA]

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