Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite hyphen problem

         

fillthy

1:20 pm on Jan 19, 2005 (gmt 0)

10+ Year Member



Hi, I now have two urls working with my mod_rewrite here they are:

[127.0.0.1...]

[127.0.0.1...]

here is my rule:

RewriteRule /([a-z-]+)-([^.]+)\-bed-breakfast.html$ /accomm_scripts/accomm_city_srch.php?city=$2&state_prov=$1 [N]

This third url wont work:

[127.0.0.1...]

Am I to believe my first part of the rule ([a-z-]+) means any lowercase character plus a hyphen? and then the second part ([^.])+ means any character? if so then why wont the third url work?

My two variables for a state_prov could be:

ontario or british-columbia

my two variables for city could be:

toronto or port-perry

Can I not just have a rule that says /([anything]+)-([anything]+)\-bed-breakfast.html...?

jdMorgan

1:44 pm on Jan 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> and then the second part ([^.]+)

means "one or more characters NOT equal to a period." Since you've changed the "tail" of the pattern from what you posted earlier, you'll need to change that now.

Also "\-bed-" does not need the leading backslash.

See the regular-expressions tutorial cited in our forum charter [webmasterworld.com] for more info.

Jim

fillthy

4:23 pm on Jan 19, 2005 (gmt 0)

10+ Year Member



Hi, thanks for the info. I now understand whats going on here...
This part is meeting this for $1 "state_prov":

RewriteRule /([a-z-]+)

but that could be "ontario" or "british-columbia" but it could also be "ontario-port" which is where my problem lies...port is the first part of a $2 "city" Is the only thing I can do is this?

ontario/port-perry-bed-breakfast.html

british-columbia/whisler-bed-breakfast.html

meaning use a / to separate the "state_prov" from the "city"?
Thanks
Phil

jdMorgan

6:55 pm on Jan 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The trick is to come up with any scheme that allows mod_rewrite to "know" how to separate the pieces of the URL into the proper query string parameters. You can do that using separator characters like "-", "+", "/", or "_", or you can do it by using a fixed number of URL-pieces per query string parameter. But yes, I think you're understanding now how to fix it (simple is best). :)

Jim