Created
April 3, 2022 10:52
-
-
Save ozkanozcan/7b6cbaf1716d9452b7a067494945e388 to your computer and use it in GitHub Desktop.
htaccess 301 redirect samples
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
# Non-www to www URLs 301 Redirect | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{HTTP_HOST} ^ozkanozcan.com$ | |
RewriteRule (.*) http://www.ozkanozcan.com/$1 [R=301,L] | |
</IfModule> | |
# www to non-www URLs 301 Redirect | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{HTTP_HOST} ^www.ozkanozcan.com$ | |
RewriteRule (.*) http://ozkanozcan.com/$1 [R=301,L] | |
</IfModule> | |
# Http to Https URLs 301 Redirect | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{SERVER_PORT} !^443$ | |
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
</IfModule> | |
# Https to Http URLs 301 Redirect | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{SERVER_PORT} ^443$ | |
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
</IfModule> | |
# Domain to Another Domain 301 Redirect | |
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
RewriteRule ^(.*)$ http://ozkanozcan.com/$1 [R=301,L] | |
</IfModule> | |
# Pages With to Without Extension(html and htm) 301 Redirect | |
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
RewriteRule ^/?(.*).(html|htm)$ /$1 [R=301,L] | |
</IfModule> | |
#Subdomain to Sudirectory 301 Redirect blog.ozkanozcan.com to ozkanozcan.com/blog | |
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
RewriteRule ^(.*)$ http://ozkanozcan.com/blog/$1 [L,NE,R=301] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment