Spaces!

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

Postby DaveS » Tue Jan 29, 2002 10:02 am

HELP!
hehe
I'm new to the whole mod_rewrite thing.... I'm trying to write a rule that will replace "space" characters with "%20"s.

Can it be done?

How can I do it?

Cheers
-Dave
DaveS
 
Posts: 1
Joined: Mon Jan 28, 2002 4:00 pm

Postby Brett » Fri Feb 01, 2002 11:55 pm

Well, URL's really aren't supposed to contain spaces, so the best thing to do is to correct the linking document and rename the document that is linked. Some browsers like MSIE will correct spaces automatically, though.

With other browsers, my guess is that the portions of the URL after the space are not even sent to the server, so the server won't be able to correct it.
Brett
 
Posts: 82
Joined: Tue Jul 10, 2001 4:00 pm
Location: yohost.com

Postby Guest » Sat Jul 27, 2002 4:11 am

I'm also very intersted in replacing spaces with %20 before apache processes the request. I've run into two problems though: I can't write regex statements, and I don't understand mod_rewrite (after reading, and reading, and reading).

If anyone could help me out, it would be greatly appreciated!

Thanks!
Guest
 

Postby Guest » Sat Jul 27, 2002 4:59 am

Btw, I currently have:


RewriteEngine on
RewriteMap wsrm-map prg:/wsremove/removespace.pl
RewriteRule ^/display.php?(.*)$ /display.php?${wsrm-map:$1}

And /wsremove/removespace.pl contains:

$| = 1;

while (<>) {
s/ /+/;
print $_;
}

which changes spaces to + (or at least it should).

I'm getting an internal server error for some reason - the perl file is chmodded 755 and chowned to the proper user and group.

Any ideas? (am I even going in the right direction, or is it possible to remove the whitespace without calling an external file at all?)

Thanks!

- Matt
Guest
 

Postby Brett » Mon Aug 05, 2002 1:55 pm

Are you doing this in an .htaccess file? You can't define a RewriteMap in an .htaccess file. That's Apache's rule, not mine. :)

And, like I said above, the problem with spaces, as I understand it, is that some browsers won't send the spaces to the server at all. If that's what you're dealing with, I'm afraid mod_rewrite can't fix it. The best solution is to simply avoid file names with spaces.
Brett
 
Posts: 82
Joined: Tue Jul 10, 2001 4:00 pm
Location: yohost.com


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 15 guests

cron