Search code examples
phpapache.htaccesshttp-headersdirectoryindex

Redirect Users based on IP Address | Apache / htaccess


I'd like to redirect users to an /index/ area of the site if they don't have my IP address.

How do I do this?

Thank you.


Solution

  • The mod_rewrite way:

    RewriteEngine on
    RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.[8-9]$ # your ip here
    RewriteCond %{REQUEST_URI} !^/index/
    RewriteRule .? /index/ [R,L]