Search code examples
php.htaccesshttp-redirect.htpasswd

How to allow betatesters with dynamic IPs to bypass the IP redirection in htaccess?


Ok, the question might sound a little complicated but I'm having an issue and I hope I can get some advice from you guys.

So I'm building a website. Currently all visitors are redirected with my .htaccess to my Coming Soon page, except from certain IP addresses. This all works fine.

Now a few of my betatesters have a dynamic IP address. So I can't give them access to the site using the method I've used until now. I could password protect the website using .htpasswd, but then I'd loose the redirection to my coming soon page, no?

Anyone who has a suggestion to give betatesters with a dynamic IP access to my website, while other visitors are redirected to my coming soon page?

Thanks a lot!


Solution

  • You can use query string and cookie.
    In your .htaccess add these lines before your "coming Soon" redirect:

    RewriteCond %{QUERY_STRING} test=betatesters1 [NC,OR]
    RewriteCond %{HTTP_COOKIE} test=betatesters1
    RewriteRule ^ - [CO=test:betatesters1:yourdomain.com,L] 
    

    The first access without cookie:

    http://yourdomain.com/?test=betatesters1
    

    I use test=betatesters1 but you can use what you want not too easy to guess