Mobile app version of vmapp.org
Login or Join
Karen161

: Redirect domain except those users coming from a specific IP address I've got a Apache web server that serves 2 domains, now in my school one domain is blocked; one isn't (same webpage for

@Karen161

Posted in: #Apache #Htaccess #Redirects

I've got a Apache web server that serves 2 domains, now in my school one domain is blocked; one isn't (same webpage for the moment). I want that if people connect to my old domain (the one that isn't blocked) to get redirected, unless it comes from the school's IP address. How would I do this, I know it has something to do with .htaccess but I don't know how to do this.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Karen161

1 Comments

Sorted by latest first Latest Oldest Best

 

@Shelton105

Try something like the following near the top of your .htaccess file (using mod_rewrite):

RewriteEngine On
RewriteCond %{HTTP_HOST} olddomain.com [NC]
RewriteCond %{REMOTE_ADDR} !203.0.113.123
RewriteRule (.*) newdomain.com/ [R=301,L]


Where 203.0.113.123 is the school's external IP address.

This is the same as any other domain to domain redirect, just with an additional condition to exclude requests coming from the above IP address.

UPDATE: If you do this redirect in your main server config, then you may need to change the above RewriteRule slightly. If it's in a <Directory> container then leave as-is, otherwise if it's directly in the server config (or virtual host) then change it to something like:

RewriteRule ^ newdomain.com%{REQUEST_URI} [R=301,L]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme