Skip to content

Instantly share code, notes, and snippets.

@codebymark
Created November 6, 2018 21:58
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 codebymark/1508bf8af601902b5f3878678b277129 to your computer and use it in GitHub Desktop.
Save codebymark/1508bf8af601902b5f3878678b277129 to your computer and use it in GitHub Desktop.
Handy htaccess - Force www and HTTPS + IP address block/redirect
# A collection of handy features
# Mark Bucknell <markbucknellcc@gmail.com>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# IP address block/redirect
# If your ip address is not in this list then redirect to the maintenance page
#Options +FollowSymlinks
#RewriteCond %{REMOTE_HOST} !^1.2.3.4 # Additional IP added by |<ip address here>
#RewriteCond %{REQUEST_URI} !=/maintenance/logo.svg
#RewriteCond %{REQUEST_URI} !=/maintenance/style.css
#RewriteRule ^(.*)$ /maintenance/index.php [R=302,L] #302 for temporary redirect
# Force HTTPS and WWW
#RewriteCond %{HTTPS} off [OR]
#RewriteCond %{HTTP_HOST} !^www\.website\.com$ [NC]
#RewriteRule ^(.*)$ https://www.website.com/$1 [L,R=301]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment