Redirect domain except those users coming from a specific IP address

Redirect domain except those users coming from a specific IP address - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the Redirect domain except those users coming from a specific IP address error on your web browser. Problem :


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.


Solution :

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 (.*) http://newdomain.com/$1 [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 ^ http://newdomain.com%REQUEST_URI [R=301,L]

We hope that this article has helped you resolve the htaccess, redirects, apache error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=