Last active
September 2, 2020 09:53
-
-
Save onemanparsons/7ae3aeb3eb5c06c63b51b35e204a5417 to your computer and use it in GitHub Desktop.
Place this .htaccess file in the root of your site. It does a couple of things: redirect http and www to https; serve site from a specific folder; and trim .html extension from URLs.
This file contains hidden or 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
RewriteEngine On | |
# Redirect http:// and www. to https:// | |
RewriteCond %{HTTPS} off [OR] | |
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC] | |
RewriteRule (.*) https://example.com/$1 [L,R=301] | |
# If the host is "example.com", serve site content from /dist folder | |
RewriteCond %{HTTP_HOST} ^example.com$ [NC] | |
# Then rewrite any request to /folder | |
RewriteRule ^((?!dist).*)$ /dist/$1 [NC,L] | |
# Disable Automatic Directory detection | |
DirectorySlash Off | |
# Trim .html extension from URL | |
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC] | |
RewriteRule ^ /%1 [NC,L,R] | |
RewriteCond %{REQUEST_FILENAME}.html -f | |
RewriteRule ^ %{REQUEST_URI}.html [NC,L] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment