[ale] apache redirect based on http referer

Brian Pitts brian at polibyte.com
Tue Jul 29 18:22:38 EDT 2008


I have a question about how to creating a RewriteCond using the http
referer with mod_rewrite for Apache 2.2.

In my test environment I have a name based virtual host 'newbb' which is
hosting an installation of phpBB2. When someone logs in to phpBB via
POSTing login.php, phpBB responds with a 302 redirect to index.php. The
web browser then GETs index.php. However, I would like to browser to
load viewforum.php instead. I could modify phpBB to redirect to
viewforum.php instead of index.php on login, but I thought I would try
accomplishing it through this bit of mod_rewrite first:

RewriteCond %(HTTP_REFERER) ^http://newbb/login\.php.*$
RewriteRule ^/index\.php$ viewforum.php?f=2 [R]

The chain of events I expected was

GET login.php
200 OK
POST login.php
302 Redirect (from phpBB)
GET index.php
302 Redirect (from mod_rewrite)
GET viewforum.php
200 OK

However, the last three don't happen. mod_rewrite doesn't think the
request for index.php matches the RewriteCond above. The message in the
log is

RewriteCond: input='%(HTTP_REFERER)'
pattern='^http://newbb/login\.php.*$' => not-matched

I have verified using Firebug that the request for index.php does
includes a referer, e.g.

http://newbb/login.php?sid=c1a3ca063842b5e4a7045c0fc278829d

Any idea what I'm doing wrong? I've read what I thought was the relevant
apache documentation and googled for examples of rewritecond's using the
referer but am none the wiser.

For the curious, the backstort is that I'm using mod_rewrite and some
small changes to phpBB2 to expose one forum through a different domain
name than the rest of a phpBB installation.

All the best,
Brian


More information about the Ale mailing list