Reputation: 702
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
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
Reputation: 7476
Try below rule,
RewriteEngine On
RewriteRule ^blog/(.*)$ http://www.new-blogdomain.com/$1 [R=301,L]
Upvotes: 0