Created
October 14, 2019 21:48
-
-
Save wesort/645e3f54ca35ac6abcdd100c0f24d2ad to your computer and use it in GitHub Desktop.
Apache .htaccess to redirect www to naked domain and remove file extensions
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
ErrorDocument 404 /404.html | |
# | |
RewriteEngine on | |
RewriteBase / | |
# | |
# Redirect all www traffic to non-www (naked domain) | |
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] | |
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] | |
# | |
# | |
# Replace html with your file extension, eg: php, htm, asp | |
RewriteCond %{REQUEST_FILENAME}.html -f | |
RewriteCond %{REQUEST_URI} !/$ | |
RewriteRule (.*) $1\.html [L] | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule ^(.+)/$ /$1 [R=301,L] | |
# | |
# | |
# REDIRECTS | |
RedirectMatch 301 ^/about$ /about/business | |
RedirectMatch 301 ^/about/$ /about/business |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment