FR STAR
FR STAR

Reputation: 702

How to domain redirect with URL content?

I recently moved my blog to separate domain, so I'm trying to define the URL redirect to my blog in my former site.

What I want to do is http://sub.exmple.com/blog/{any page} should redirect to http://www.new-blogdomain.com/{old page url}

The code I'm trying is:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.exmple.com [NC]
RewriteRule ^(.*)$ http://www.new-blogdomain.com/$1 [R=301,L]

The above code works if I go to sub.exmple.com/{any page} and goes to http://www.new-blogdomain.com/{old page} but this RULE should apply if my old URL contain blog keyword http://sub.exmple.com/blog/ .

Upvotes: 0

Views: 70

Answers (2)

Tom Kuschel
Tom Kuschel

Reputation: 765

Try:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\.exmple\.com [NC]
RewriteRule ^\/?blog\/(.*)$ http://www.new-blogdomain.com/$1 [R=301,L]

instead of ^\/?blog\/(.*)$, you can try either ^blog\/(.*)$ or ^\/blog\/(.*)$, depending on server configuration

Upvotes: 1

Abhishek Gurjar
Abhishek Gurjar

Reputation: 7476

Try below rule,

RewriteEngine On
RewriteRule ^blog/(.*)$ http://www.new-blogdomain.com/$1 [R=301,L]

Upvotes: 0

Related Questions