Last active
January 13, 2023 16:19
-
-
Save davecurrierseo/ecbc2121cae10df4da5f0a5c776055bc to your computer and use it in GitHub Desktop.
.htaccess Redirects
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
# Force HTTPS | |
RewriteCond %{HTTPS} !=on | |
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com [NC] | |
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] | |
# Sub-Domain Only To A Specific URL | |
RewriteCond %{HTTP_HOST} ^sub\.old-domain\.com [NC] | |
RewriteCond %{REQUEST_URI} ^/$ | |
RewriteRule ^(.*)$ http://www.domain.com/url/ [R=301,L] | |
# Rewrite a specific URL | |
RewriteCond %{REQUEST_URI} ^/example/?$ [NC] | |
RewriteRule ^(.*)$ http://www.domain.com/url/ [R=302,L] | |
# Root Domain Only To Specific URL | |
RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.com [NC] | |
RewriteCond %{REQUEST_URI} ^/$ | |
RewriteRule ^(.*)$ http://www.domain.com/url-1/url-2/ [R=301,L] | |
# Rewrite JUST the domain (leave the URL slugs) | |
RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.com$ [NC] | |
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L] | |
# Remove query strings , change root domain, leave the URLs | |
RewriteCond %{HTTP_HOST} ^sub\.old-domain\.com$ [NC] | |
RewriteCond %{QUERY_STRING} . | |
RewriteRule ^(.*)$ http://www.domain.com/$1? [R=301,L] | |
# Sub-Domain Only w/out Query Strings | |
RewriteCond %{HTTP_HOST} ^sub\.old-domain\.com$ [NC] | |
RewriteRule ^(.*)$ http://www.domain.com/$1? [R=301,L] |
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
# ------------------------------------------------------------------------------ | |
# Enforce HTTPS | |
# ------------------------------------------------------------------------------ | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{HTTP:X-Forwarded-Proto} =http | |
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment