使用htaccess进行条件重定向

时间:2014-07-07 20:16:41

标签: php apache .htaccess mod-rewrite rewrite

我有一个网站:blog.example.com。

我希望blog.example.com转到example.com/news

但我希望blog.example.com/tag/mytagblog.example.com/category/mycategory转到example.com/tag/mytagexample.com/category/mycategory

到目前为止,我有这样的.htaccess,但当然它不起作用:

RewriteEngine on
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteRule ^(.*)$ http://www.example.com/news/ [R=301,L]

1 个答案:

答案 0 :(得分:1)

您可以在blog.example.com的根.htaccess中使用它:

RewriteEngine on

RewriteRule ^/?$ http://www.example.com/news [R=301,L]
RewriteRule ^(.+)$ http://www.example.com/$1 [R=301,L,NE]