htaccess多次重写url到同一个文件夹

时间:2013-11-24 20:45:53

标签: .htaccess url-rewriting

我是使用htaccess的新手,我想知道我有3个网址我要重写到同一个文件夹

   /articles-pages.php?page_name=$1
   /articles-posts.php?page_name=$1     
   /articles-interviews.php?page_name=$1

并希望他们都重写为文章/ $ 1

是否可能或者我必须将它们放在单独的文件夹中。任何帮助将非常感激。


更新:我的htaccess文件看起来像这样

 ErrorDocument 404 http://www.about-muscle.com/404.php
 ErrorDocument 500 http://www.about-muscle.com/500.php

 RewriteEngine On

 RewriteCond %{QUERY_STRING} (?:^|&)page_name=([^&]+)(?:&|$) [NC]
 RewriteRule ^articles-(interviews|pages|posts)\.php$ /articles/%1? [R=301,L,NE]


 RewriteEngine on

 RewriteRule ^(index\.php|bodybuilding\-links\.html) - [L]
 RewriteRule ^(index\.php|bodybuilders\-links\.html) - [L]
 RewriteRule ^(index\.php|personal\-training\-links\.html) - [L]
 RewriteRule ^(index\.php|fitness\-links\.html) - [L]
 RewriteRule ^(index\.php|supplements\-links\.html) - [L]
 RewriteRule ^(index\.php|nutrition\-links\.html) - [L]
 RewriteRule ^(index\.php|female\-fitness\-links\.html) - [L]
 RewriteRule ^(index\.php|weight\-loss\-links\.html) - [L]
 RewriteRule ^(index\.php|magazine\-links\.html) - [L]
 RewriteRule ^(index\.php|equipment\-links\.html) - [L]
 RewriteRule ^(index\.php|health\-links\.html) - [L]
 RewriteRule ^(index\.php|other\-links\.html) - [L]
 RewriteRule ^(index\.php|links\.html) - [L]

 RewriteEngine On
  RewriteCond %{HTTP_HOST} ^about-muscle.com
  RewriteRule (.*) http://www.about-muscle.com/$1 [R=301,L]

 RewriteEngine On
  RewriteRule ^(.*)\.html$ $1.php

 Options +FollowSymLinks

 RewriteEngine on

 RewriteRule exercises/name/(.*)/ exercises/detail.php?name=$1
 RewriteRule exercises/name/(.*) exercises/detail.php?name=$1   

 RewriteEngine on

 RewriteRule exercises/muscle/(.*)/ exercises/muscle.php?page_name=$1
 RewriteRule exercises/muscle/(.*) exercises/muscle.php?page_name=$1    

 RewriteEngine on

 RewriteRule exercises/type/(.*)/ exercises/type.php?page_name=$1
 RewriteRule exercises/type/(.*) exercises/type.php?page_name=$1

 RewriteEngine on

 RewriteRule exercises/equipment/(.*)/ exercises/equipment.php?page_name=$1
 RewriteRule exercises/equipment/(.*) exercises/equipment.php?page_name=$1

 RewriteEngine on

 RewriteRule exercises/mechanics/(.*)/ exercises/mechanics.php?page_name=$1
 RewriteRule exercises/mechanics/(.*) exercises/mechanics.php?page_name=$1

 RewriteEngine on

 RewriteRule exercises/force/(.*)/ exercises/force.php?page_name=$1
 RewriteRule exercises/force/(.*) exercises/force.php?page_name=$1

 RewriteEngine on

 RewriteRule writers/(.*).php writers/$1/

 RewriteRule writers/(.*)/ writer-pages.php?page_name=$1
 RewriteRule writers/(.*) writer-pages.php?page_name=$1

 RewriteEngine on

 RewriteRule go/(.*)/ goto.php?m=$1
 RewriteRule go/(.*) goto.php?m=$1  

1 个答案:

答案 0 :(得分:0)

您可以将此代码放在DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+articles-(?:interviews|pages|posts)\.php\?page_name=([^\s&]+) [NC]
RewriteRule ^ /articles/%1? [R=302,L]

RewriteRule ^articles/([^/.]+)/?$ /article-pages.php?page_name=$1 [L,QSA,NC]