Reputation: 31
I have recently stopped using a subdomain for my blog, i need to forward all links that use that domain to the same link path but on my main domain.
Example being:
needs to redirect to :
I can redirect the subdomain itself so
-blog.example.com/
goes to
but as soon as I try to redirect a page it doesn't redirect and doesn't load. Can anyone shed some light on it? I currently have this in my htaccess for my main redirect:
RewriteCond %{HTTP_HOST} ^blog\.example\.com [NC]
RewriteRule (.*) http://www.example.com/blog/$1 [L,R=301]
I have other subdomain redirects going on but none wildcard redirect.
Upvotes: 2
Views: 2978
Reputation: 74098
In your example, you want to redirect from
blog.example.com/blog/sales/blog-title
to
www.example.com/blog/sales/blog-title
But in your rule, you insert another subdirectory blog
in the substitution part, which gives
www.example.com/blog/blog/sales/blog-title
instead, and an error 404 as a result.
To redirect from one domain to another with the exact same request path, use
RewriteCond %{HTTP_HOST} ^blog\.example\.com$ [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI} [L,R]
When it works as it should, you may replace R
with R=301
. Never test with R=301
.
Upvotes: 3