Skip to content

Instantly share code, notes, and snippets.

@wesort
Created October 14, 2019 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesort/645e3f54ca35ac6abcdd100c0f24d2ad to your computer and use it in GitHub Desktop.
Save wesort/645e3f54ca35ac6abcdd100c0f24d2ad to your computer and use it in GitHub Desktop.
Apache .htaccess to redirect www to naked domain and remove file extensions
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