Created
December 10, 2023 11:55
-
-
Save BenceSzalai/0277c9cbe5b3f905b6bbc755c667e7a2 to your computer and use it in GitHub Desktop.
Redirect www/non-www variants
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ensure canonical domain | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
# Use one of these two: | |
# Rewrite www.domain.com -> domain.com | |
RewriteCond %{HTTP_HOST} . | |
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC] | |
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] | |
# OR: | |
# Rewrite domain.com -> www.domain.com | |
RewriteCond %{HTTP_HOST} !^$ | |
RewriteCond %{HTTP_HOST} !^www\. [NC] | |
RewriteCond %{HTTP_HOST} (.+)$ | |
RewriteRule ^(.*)$ https://www.%1/$1 [R=301,L] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment