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

Posted by Shawn on Stack Overflow See other posts from Stack Overflow or by Shawn
Published on 2010-05-20T06:38:42Z Indexed on 2010/05/20 6:40 UTC
Read the original article Hit count: 222

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about .htaccess

Related posts about redirect