Forum Moderators: phranque

Message Too Old, No Replies

Rewrite Rule Clarification

         

varunkrish

8:01 am on Jun 7, 2005 (gmt 0)

10+ Year Member



i tried rewriting some urls...
RewriteRule ([^-]+)-([^-]+)-(photos)\.php$ /photos.php?mak=$1&mod=$2 [NC,L]

points to photos.php?mak=$mak&mod=$mod

this rule works only if the $mod does not contain any "-"

if the $mod contains any "-" it automatically uses the Rule below

RewriteRule ^([^-]+)[-](.*)\.php$ /phone.php?mak=$1&mod=$2 [NC,L]

i want to get rid of the .* as pointed.

is there any way i can check for 2 occurences of a "-"

the model field will not have more than 2 "-" s

my urls will be either
(1)brand-model.php
or
(2)brand-m-od-el.php

(1)its solved
RewriteRule ^([^-]+)[-]([^-]+)\.php$ /phonemodel.php?mak=$1&mod=$2 [NC,L]

(2)Clueless

shall i go for RewriteCond?

needing your help...thanks

varun

varunkrish

8:02 am on Jun 7, 2005 (gmt 0)

10+ Year Member



Or shall i try to remove the "-" from my models feild..

is it advisable to use urls like

brand-model.php

or

brand-mod-e-l.php

thanks,
varun

jdMorgan

1:04 am on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This thread is apparently related to some other thread, but I'm not sure which one.

The basic problem is to declare a "separator" character that will not (and must not) appear in the brand name. Otherwise, you will not be able to write a regular expressions pattern to separate the brand and model number. So, the separator character must be unique.

If you are sure that hyphens "-" will never appear in the brand name, then the rule


RewriteRule ^([^-]+)-(.+)\.php$ /phonemodel.php?mak=$1&mod=$2 [NC,L]

should work, and will allow the model number to contain hyphens or periods.

Jim