Sign up ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I need to forward existing subdomain links to the root domain as the subdomain no longer exists. I have tried so many different lines of code in my .htaccess file and can not get the redirect to work.

The links to the subdomain look like:

Can anyone suggest any code for me?

share|improve this question

1 Answer 1

To redirect requests for to

RewriteEngine on
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^(.*)$$1 [R=301,L]

To redirect requests for to

RewriteEngine on
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^(.*)$ [R=301,L]
share|improve this answer
Thanks for your reply Nick. I just need to redirect from to (no uri) – Lin Aug 17 '12 at 9:48
@Lin Thanks for the information. I've updated my answer with a rewrite rule that drops the path when redirecting. – Nick Aug 17 '12 at 9:57
thanks but it's not working for me. Maybe I'm placing it in the wrong spot in my .htaccess # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On [I tried the code here] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress [I also tried the code here] other working 301s are here I can't seem to format this so it's easy to read. – Lin Aug 18 '12 at 3:08
@Lin I've tested this on a live site and the rules are working for me. Is there still a DNS record for the subdomain in your domain control panel? Or, if you're using nameservers and managing the subdomain with cPanel or similar, is there still a subdomain entry in your cPanel account? Removing either of these will break the redirection because there still needs to be a record that the subdomain existed. Let me know if that's not clear and I'll try to help. – Nick Aug 19 '12 at 12:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.