.htaccess and forward slashes

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
phpdevuk
Forum Contributor
Posts: 220
Joined: Mon Jul 04, 2005 5:31 am
Location: UK
Contact:

.htaccess and forward slashes

Post by phpdevuk »

hello, I'm trying to make human readable urls, using the titles of products as link names with mod rewrite. One of my products has a forward slash in its name, trips everything over nicely. I've tried various methods of getting it working, and annoyingly my regex works in regex workbench just not with mod rewrite! ok see below,

.htaccess

Code: Select all

RewriteEngine On
RewriteRule ^productDetails/-/(.*)/-/(.*)/-/$ productDetails.php?category=$1&product=$2 [L]
my urls look like
http://webserver/website/web/productDet ... ct-name/-/

I'm stumped, think I'm just gonna ban forward slashes!
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Maybe like this... what was the problem anyway?

Code: Select all

RewriteRule productDetails/-/((?:(?!/-/).)+)/-/((?:(?!/-/).)+)/-/$ productDetails.php?category=$1&product=$2
I'm not sure how legal lookaround in Apache is though.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Ok I think I have found the problem. Your server is running mod_negociate and that is converting productDetails/ into productDetails.php/ before your rewrite rule is run. The following worked fine on my server (Apache 2.0.54)

Code: Select all

RewriteEngine On
RewriteRule productDetails(?:\.php)?/-/((?:(?!/-/).)+)/-/((?:(?!/-/).)+)/-/$ productDetails.php?category=$1&product=$2 [L]
User avatar
phpdevuk
Forum Contributor
Posts: 220
Joined: Mon Jul 04, 2005 5:31 am
Location: UK
Contact:

Post by phpdevuk »

cool, thanks I will give it a try tomorrow
Post Reply