简体   繁体   English

不同的htaccess目录和子目录重定向

[英]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 mysite.tld/directory/ 将前往 > mysite.tld/page.php?q=directory
  2. mysite.tld/tags/directory/ is going to > mysite.tld/tag.php?q=directory mysite.tld/tags/directory/ 将前往 > mysite.tld/tag.php?q=directory

I have made an htaccess file at the root of my site wiht the folling code:我使用以下代码在我的站点的根目录创建了一个 htaccess 文件:

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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