How to redirect to with .htaccess?



I would like to redirect to I used the Rewrite of .htaccess. I wrote this:

RewriteCond %{HTTP_HOST} ^sub.example.+$ [NC]
RewriteRule ^$1 [R=301,L]

I already activate the rewrite with: sudo a2enmod rewrite.

And I already rewrite to with:

RewriteCond %{HTTP_HOST} ^example.+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Do you know how I have to write my Rewrite rules in this case?


If you specify the domain name, you can use one rule for both cases:

RewriteCond %{HTTP_HOST} ^(sub\.)?example.+$ [NC]
RewriteRule ^{REQUEST_URI} [R=301,L]

Answered By – Croises

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More