Mobile app version of vmapp.org
Login or Join
Harper822

: Using mod_rewrite to check for existence of a cookie I have an 'internal' website at my company that i'd like to allow outside access to via a reverse proxy with an Apache Server. The wrinkle

@Harper822

Posted in: #ModRewrite #ReverseProxy

I have an 'internal' website at my company that i'd like to allow outside access to via a reverse proxy with an Apache Server.

The wrinkle here is that I only want particular Mobile Users accessing this reverse proxy.

I've created a very generic mobile app that will ALWAYS pass a cookie like MOBILEUSER=TRUE.

Is it possible to write a mod_rewrite rule to check for the existence of that cookie and ONLY allow requests with that cookie and value through?

thanks for any help!!

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Harper822

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

You can return a "403 Forbidden" if the cookie is not set with something like the following:

RewriteEngine On
RewriteCond %{HTTP_COOKIE} !bMOBILEUSER=TRUEb
RewriteRule ^ - [F]


The ! before the CondPattern simply negates the pattern. b is word boundary, so it will only match that exact name/value pair, anywhere in the cookie.

A single ^ (start of string anchor) for the RewriteRule pattern matches everything. A single - (hyphen) for the substitution doesn't do anything, the URL is not rewritten (but the substitution is ignored anyway when using the F flag). And the F flag results in a 403 being served (this also implies an L flag - so processing stops).

Obviously, unless you are using SSL then the cookie can be sniffed.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme