+ characters within mod_rewrite rules

Discuss practical ways rearrange URLs using mod_rewrite.

+ characters within mod_rewrite rules

Postby futurity » Tue Apr 12, 2005 5:39 am

Hi All,

I've currently got the following rule in my mod_rewrite which works:

RewriteRule ^([A-Za-z0-9_-]+)/$ test.php?level1=$1

if there is a directory specified "abcd/" thenn it called the php script passing the directory name as the parameter.

Now i'd like to use php urlencode when i'm making up URL on the fly. When i use this command, spaces are replaced by '+' characters. I've tried the following line (added an escaped + character to tha pattern match) to match the plus characters but it doesn't work:

RewriteRule ^([\+A-Za-z0-9_-]+)/$ test.php?level1=$1

I can't se why it won't work! Any ideas?

Many thanks in advance.

Neil
futurity
 
Posts: 3
Joined: Tue Apr 12, 2005 5:31 am
Location: UK

Postby Caterham » Tue Apr 12, 2005 1:49 pm

add a space by \(space):
Code: Select all
RewriteRule ^([\ A-Za-z0-9_-]+)/$ test.php?level1=$1 [L]
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm

Same Sort Of problem

Postby Jim » Wed Apr 20, 2005 2:13 pm

Hi I am having the same sort of problem, I would like to have urlencode encode the url. I am using:

RewriteRule ^cat/(.*)/(.*)$ sub_category.php?cat=$1&artist=$2 [L]

It works for such urls without the + sign in them,such as a space. but then when I have a url with the + sign it doesn't. The url ends up as
http:/.../Shop+Seats+%2B+Stools
I Believe this is a mod_rewrite problem because it was working before I strated mod_rewrting the site.

Thanks

Jim
Jim
 

more info

Postby Guest » Wed Apr 20, 2005 7:55 pm

Hi, the problem seems to be that the mod_rewrite is somehow stiping out the plus sign or something. Because when I check the $_GET variable and the plus sign is gone. When I turned off the mod_rewrite and just use
echo "<a href='/sub_category.php?cat=".urlencode(Heaters + Stoves)."' ....
The $_GET still contains the plus sign.

Thanks Again :)
Guest
 


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 20 guests

cron