Monday, July 07, 2008

Redirect and masking with mod_rewrite

I'm not sure if this will work for anyone else in the world except me, since mod_rewrite is such a tricky beast (and apparently powered by voodoo).

I managed to mask the JSP on my site which was something like:


Simple! I thought. Mod_rewrite can handle this; before I was hit with:

"You don't have permission to access /doSomethingGood/ on this server"

So I searched around the web here and there and found out that you need to 'enable' mod_proxy. So I did, by uncommenting the line in my httpd.conf:

LoadModule proxy_module modules/

I still had the same problem though and looking through my Rewrite Log (which was set to loglevel 3) everything seemed normal and the only meaningful message was "go-ahead with proxy request proxy." So all seemed fine even though it wasn't working.

After another round of searches I just tried my luck and uncommented all other modules that are related to mod_proxy. Lo' and behold, it all began to work:

LoadModule proxy_module modules/
LoadModule proxy_connect_module modules/
LoadModule proxy_http_module modules/
#LoadModule proxy_ftp_module modules/

Now my virtualhost tag looks something like:

<VirtualHost *>

DocumentRoot "D:\website\webapps\mySiteBlahBlah"

RewriteEngine On
RewriteRule .* - [F]
RewriteRule /doSomethingGood/([A-Z]+).html$1 [proxy,QSA]
RewriteLog "D:\Program Files (x86)\Apache Group\Apache2\logs\mod_rewrite.log"
RewriteLogLevel 1


I hope this helps at least someone out there.

Many thanks to all these sites for helping me along:
Apache: mod_rewrite documentation
Apache: mod_proxy documentation

No comments:

Post a Comment