Reputation: 1
My site has a subdomain: docs.example.com and many folders within: docs.example.com/math, docs.example.com/science, docs.example.com/language and so on. All these URLs are indexed in Google. I need the subdomain and its subfolders to be redirected to the main URL: www.example.com.
I need to do a 301 redirect because of SEO. I have access to .htaccess in the host server. I tried this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^docs.example.com$
RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]
Works fine for docs.example.com but for docs.example.com/math I get a 404 error. Everything beneath docs.example.com MUST be 301 redirected, all subfolders and files.
Thanks for your help in advance
Upvotes: 0
Views: 178
Reputation: 133538
Please following htaccess rules at top of your .htaccess Rules file. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?docs\.example\.com$ [NC]
RewriteRule ^(.*)/?$ http://www.example.com/$1 [R=301,NE,L]
Additional notes: With rules following are suggestions/improvements.
Upvotes: 3