开发者

Using htaccess redirect all files to another domain but exclude the root domain

Recently, I want to restructure and redesign my website, my old website located at www.example.com, there are lots of blog posts under this domain, like:

www.example.com/post1
www.example.com/post2
www.example.com/post3
...

I can redirect all those posts to another sub domain points in another folder (not sub folder), (if I put all those posts in a sub folder, it will recursive the subfolder name) , anyway, it works for me by using the code below:

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

But there is one things I want to do is not redirect the main domain开发者_如何学编程, only all the posts.

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/blog/ # the new blog
# I tried below
#RewriteCond %{REQUEST_URI} !^/$
#RewriteCond %{REQUEST_URI} !^www.example.com$
RewriteRule ^(.*)$ http://pre.example.com/$1 [L,R=301]

Is it possible I can do that? Thx.


Try this rule:

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

Here .+ will match possible URI path but / (note that the path prefix is removed before testing the pattern).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜