Web Hosting Talk







View Full Version : mod_rewrite Help Needed


loopforever
07-29-2002, 09:54 PM
Hey all,

I need a bit of help with mod_rewrite - or anything else that will help me with this problem.

I have a problem with a specific browser, that does not urlencode its links, so if there is a space in the url, it is sent directly to apache with the space, rather than a %20. So, you're probably saying, "just use another browser, or get rid of the space before the request is sent." Unfortunately, this can't be done.

I have a patch for apache that will fix this, but I cannot apply it because I'm running Ensim on this server and I cannot recompile apache.

I want to use a mod_rewrite statement to remove the spaces from the request before it is processed by apache, my problem is that after reading everything I could find on the subject, I still don't grasp how to use it to suit my needs.

I attempted using a rewritemap to call a perl script I wrote to remove the spaces, but I get an Internal Server Error (script is properly chmodded and such).

I tried sending fake 200 headers back to the browser, no luck.

I tried using HTTP::Request and HTTP::Request::Common to send a modifed request to apache, no luck.

What I'm interested in finding out, is if anyone could help me write a rewrite statement that uses regex to remove the space without calling an external file.

If anyone could help me with this problem, I would really appreciate it. Thanks!

bombino
07-29-2002, 09:56 PM
Why do you need the %20's converted to spaces?

loopforever
07-29-2002, 09:57 PM
You have it backwards, I need spaces converted to %20.

mwatkins
07-30-2002, 01:27 AM
I think you were on the right track, looking to Perl to solve this.

http://www.engelschall.com/pw/apache/rewriteguide/#ToC44

From the guide:

RewriteEngine on
RewriteMap quux-map prg:/path/to/map.quux.pl
RewriteRule ^/~quux/(.*)$ /~quux/${quux-map:$1}


and map.quux.pl is:

$| = 1;

while (<>) {
s|^foo/|bar/|;
print $_;
}




Instead implement a substitution routine that replaces spaces with %20.

Going to be a performance hit though. You will certainly want to incorporate a browser test (hopefully the offending browser complies with this!) so that only the offending browser causes the code to fire off... i.e.

RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3.*
RewriteRule ..... your rule

loopforever
07-30-2002, 08:49 AM
Actually, that web site is the exact place I got the idea for the rewrite map :-p.

I'm running the same exact thing, but I modifed the "replace" statement in the perl script to:

s|^ /|%20/|;

I don't even really know if this is correct - I haven't touched perl in years. I think that this would be correct also:

s/ /%20/;

No idea, I did some reading up on this subject also though. And regex: no comprende. :rolleyes:

What I did,was point the prg: to /wsremove/wsremove.pl chmodded 755, put the rewrite code in httpd.conf and ran it. It came up with an Internal Server Error. So, I noticed there was no path to perl in the script, so I added it - still no luck.

Any ideas? Thanks!

elsmore1
07-30-2002, 11:35 PM
Originally posted by loopforever
Actually, that web site is the exact place I got the idea for the rewrite map :-p.

I'm running the same exact thing, but I modifed the "replace" statement in the perl script to:

s|^ /|%20/|;

I don't even really know if this is correct - I haven't touched perl in years. I think that this would be correct also:

s/ /%20/;

No idea, I did some reading up on this subject also though. And regex: no comprende. :rolleyes:

What I did,was point the prg: to /wsremove/wsremove.pl chmodded 755, put the rewrite code in httpd.conf and ran it. It came up with an Internal Server Error. So, I noticed there was no path to perl in the script, so I added it - still no luck.

Any ideas? Thanks!

your second try was closer to what you need... that s|^ /|%20/|; line won't do what you want....

use....
s/\s/\%20/g;
to replace all spaces with %20 and make sure you are sending the relevant parts of the url to the perl script to be rewritten.