I've an old subdomain that was being used as a whitelabel.

I'd like to redirect the subdomain to a page on my main domain.

I was thinking the best way would be a htaccess redirect.

RewriteCond %{HTTP_HOST} ^mysubdomain\.example\.com$ [NC]
 RewriteRule ^(.*) https://www.example.com/newpage.html/$1 [L,R]

I've a feeling the above rewrite is not correct.

I've also got another redirect in my htaccess for the main domain so I'm not sure where to put this in?

Finally, is there another way of doing this?

1 Answer 1


You are close.

RewriteCond %{HTTP_HOST} ^sub-domain\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/newpage.html [R=301,L]


RewriteCond %{HTTP_HOST} ^sub-domain\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/folder/ [R=301,L]

I included the second example in case you want it.

I also use R=301,L. R,L is nearly the same thing defaulting to a 302 redirect which is temporary whereas a 301 is permanent. A 301 is what you want. I like to be explicit when using R.

Notice I use both the ^ and $ to properly define the beginning and end of any regex (regular expression). I have learned to avoid misinterpretation where possible. Again, I like to be explicit.

  • 1
    @DocRoot Yes. Of course. Cheers mate! I have not written any new redirects in years. Thanks for the reminder. Updated the answer. Again, Thank You.
    – closetnoc
    Commented Oct 14, 2019 at 0:32
  • Thank you very much @closetnoc!
    – Dtheme
    Commented Oct 15, 2019 at 2:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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