url ending with a '/' breaks GET vars

Discuss practical ways rearrange URLs using mod_rewrite.

url ending with a '/' breaks GET vars

Postby mattock » Tue Jul 29, 2008 2:09 am

Hi

I have the following url:

www.mysite.com/venues/one/two/three
which re-writes to:
www.mysite.com/venues.php?id1=one&id2=two&id3=three

using the following rule:
Code: Select all
RewriteRule ^venues/(.*)/(.*)/(.*)$ venues.php?id1=$1&id2=$2&id3=$3 [L]


how ever, when i add a forward slash to the end of the url, the first two GET vars are concatenated, eg


www.mysite.com/venues/one/two/three/
re-writes to:
www.mysite.com/venues.php?id1=one/two&id2=three&id3=

Little stuck, how would i fix this?

Thanks
mattock
 
Posts: 2
Joined: Tue Jul 29, 2008 12:36 am

Postby richardk » Tue Jul 29, 2008 11:51 am

.* is greedy, the first .* matches as much as possible. You should write an appropriate character class (instead of [^/] in below).
Code: Select all
Options +FollowSymLinks -MultiViews

RewriteEngine On

RewriteRule ^venues/([^/]+)/([^/]+)/([^/]+)/?$ /venues.php?id1=$1&id2=$2&id3=$3 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mattock » Wed Jul 30, 2008 5:41 am

....ok, thats great

Cheers
mattock
 
Posts: 2
Joined: Tue Jul 29, 2008 12:36 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 25 guests

cron