Apache httpd rewrite based on cookie value

Solution Verified - Updated -

Environment

  • Apache httpd
  • Red Hat Enterprise Linux (RHEL)
  • Red Hat JBoss Web Server (JWS)
  • Red Hat JBoss Core Services (JBCS)

Issue

  • How can we do a rewrite or redirect in httpd based upon the value of a cookie?

Resolution

  • Use mod_rewrite with a RewriteCond that checks the HTTP_COOKIE variable and then rewrite as desired, for example:

    RewriteEngine On
    RewriteCond %{HTTP_COOKIE}   ^.*COOKIENAME=COOKIEVALUE.*$
    RewriteRule ...
    

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments