views:

125

answers:

1

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.

A: 

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).

Gumbo
thanks for the suggestion, Gumbo. Tried it and works.
Shawn