Skip to content

Instantly share code, notes, and snippets.

@benhuson
Last active May 15, 2019 01:26
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benhuson/6f1b9d192cc1cab31093 to your computer and use it in GitHub Desktop.
Save benhuson/6f1b9d192cc1cab31093 to your computer and use it in GitHub Desktop.
.htaccess rules for redirecting if IP address does not match.
# Redirect other IP addresses
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Single IP Address
RewriteCond %{REMOTE_HOST} !^00.00.00.00
# Multiple IP Addresses
RewriteCond %{REMOTE_HOST} !^(00.00.00.00|00.00.00.00)
RewriteRule .* http://www.example.com/ [R=301,L]
</IfModule>
@benhuson
Copy link
Author

Or so ensure maintenance page is not redirected in infinite loop:

# MAINTENANCE-PAGE REDIRECT
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{REMOTE_ADDR} !^00.00.00.00
 RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
 RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
 RewriteRule .* /maintenance.html [R=302,L]
</IfModule>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment