Difficult problem (or newbie error)

New to mod_rewrite? This is a good place to start.

Difficult problem (or newbie error)

Postby hagbard » Mon Nov 21, 2005 3:18 pm

I am having real issues trying to get a simple rewrite working:
I have a main ISP website (www.hagbard.plus.com) and a personal domain (goui.net) the points to it, so without any rewriting:

http://www.hagbard.plus.com == http://[www.]goui.net

My requirements are:

1: http://goui.net/<anything> --> http://www.hagbard.plus.com/goui/<anything>

To provide basic virtual server support.

Additionally any CGI scripts are hosted on a different server (ccgi.hagbard.plus.com) so I need the additional rule:

2: http://www.hagbard.plus.com/<anypath>.cgi --> http://ccgi.hagbard.plus.com/cgi-bin/<anypath>.cgi

My initial solution ran afoul of the double path component bug (I am running on 1.3.x and cannot change it) but I got around that. My latest (mostly working) rewrite rule is:
----
RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?goui\.net$ [NC]
RewriteCond %{REQUEST_URI} !^/goui/
RewriteRule ^(.*)$ goui/$1

RewriteCond %{HTTP_HOST} ^(www\.)?goui\.net$ [NC]
RewriteCond %{REQUEST_URI} ^(/goui)?(/.*\.cgi)(/[^/]*\.cgi)?$
RewriteRule ^(.*)$ http://ccgi.hagbard.plus.com/cgi-bin/goui%2 [L,R]

RewriteCond %{REQUEST_URI} ^(/.*\.cgi)$
RewriteRule ^(.*)$ http://ccgi.hagbard.plus.com/cgi-bin%1 [L,R]
----

This doesn't try and chain the rules (that was what caused the double path component problem) but instead has 3 rules for the different cases.

This actually works (although I am quite willing to believe that it is not the best way to do it).

However I've just noticed that if I rewrite:
http://goui.net/foo.cgi?x=%25
I get:
http://ccgi.hagbard.plus.com/cgi-bin/go ... gi?x=%2525

Which is obviously wrong because it has double encoded the % character. I note that it doesn't double encode spaces (it leaves them as +) so it's obviously not just encoding everything.

Does it look like it anything I am doing that's causing this? Can anyone point me at an easier way to do what I want (I'll use a rewrite map if I can access that from my user space htaccess file).

Please help, this is very important to me right now!
Cheers,
David.
hagbard
 
Posts: 2
Joined: Mon Nov 21, 2005 2:58 pm

Return to Beginner's Corner

Who is online

Users browsing this forum: Majestic-12 [Bot] and 2 guests

cron