Forum Moderators: phranque

Message Too Old, No Replies

Problem with Two Dashes

is this a Unix thing?

         

fjpapaleo

5:46 pm on Apr 25, 2006 (gmt 0)

10+ Year Member



I'm having a problem when using products with a dash in the name.

RewriteRule ^page-([^.]+)-([^.]+)\.html$ /page.php?model=$1&make=$2 [L]

works fine for page-sedan-ford.html

runs into trouble with page-sedan-mercedes-benz.html

Is this a problem only on a Unix server? I think it has something to do with PERL maybe? Any ideas on getting around this?

zCat

6:04 pm on Apr 25, 2006 (gmt 0)

10+ Year Member



The problem is probably with your regex. Certainly won't have anything to do with Perl.

The regex should probably look more like this (untested):

^page-([^-]+?)-([^\.]+)\.html$

i.e. "page [hyphen] (everything that's not a hyphen) hyphen (everyhing that's not a full stop) [fullstop] html

assuming that's the pattern you want to match.

fjpapaleo

1:14 am on Apr 26, 2006 (gmt 0)

10+ Year Member



Yeah, I had tried that along with a few other things but nothing seems to work. Ireally don't understand why
RewriteRule ^page-([A-Za-z\-]+)-([A-Za-z\-]+)\.html$ /page.php?model=$1&make=$2 [L]
doesn't work. I think it's sending back:

php?model=sedan-mercedes&make=benz

I can't believe nobody has had this problem before. I really don't know PERL but from what I've been reading up on I think it really has something to do with that and Unix. Oh well, thanks for trying anyway.

zCat

2:05 am on Apr 26, 2006 (gmt 0)

10+ Year Member



I can't believe nobody has had this problem before. I really don't know PERL but from what I've been reading up on I think it really has something to do with that and Unix.

Well, if you really want to keep thinking that, I can't help you :-/. The only connection with Perl is possibly that Apache uses the PCRE library; but the problem is that your regex is not working because it's evidently wrong.

jdMorgan

2:11 am on Apr 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



By including the "\-" in the first subpattern, you're allowing that subpattern to match "sedan-mercedes".

Try this instead, after flushing your browser cache:


RewriteRule ^page-([a-z]+)-([a-z\-]+)\.html$ /page.php?model=$1&make=$2 [NC,L]

(Also by using [NC], you avoid needing the redundant A-Za-z check.)

Jim

fjpapaleo

2:32 am on Apr 26, 2006 (gmt 0)

10+ Year Member



OMG, I can't believe I missed that. Just when you think you're starting to get this stuff :) Thanks once more JD. I'm off to start re-writing my url's.............again.