Welcome to WebmasterWorld Guest from 54.227.5.198

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Problem with using only hyphens in rule

     

Zacharias

10:04 am on Aug 9, 2007 (gmt 0)

5+ Year Member



I have a rule a bit like this

RewriteRule ^([a-zA-Z0-9_\-]+)/([a-zA-Z0-9_\-]+)/([a-zA-Z0-9]+)-([a-zA-Z0-9_\-]+)-([a-zA-Z0-9_\-]+)/index.php?$ index.php?sec=$1&cat=$2&cat1=$3&cat2=$4&cat=$2

I have basically got a problem with the last part

/([a-zA-Z0-9]+)-([a-zA-Z0-9_\-]+)-([a-zA-Z0-9_\-]+)/

This rule cannot use 3 variables in the last part separated by a hyphen.

It works if I use a underscore to separate the last part, however I would rather avoid using underscores or anything other than a slash.

Is it normal to have problems doing this type of thing with rewrite rules?

g1smd

4:17 pm on Aug 9, 2007 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



One piece of advise I can offer is that A-Za-z can be simplified to a-z and an [NC] tag added to the end to cater for aNyCase.

I hear that it also works faster with that.

jdMorgan

5:26 pm on Aug 9, 2007 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Use the [NC] flag:
 ^([a-zA-Z0-9_\-]+)/([a-zA-Z0-9_\-]+)/([a-zA-Z0-9]+)-([a-zA-Z0-9_\-]+)-([a-zA-Z0-9_\-]+)/index.php?$ 

becomes
 ^([a-z0-9_\-]+)/([a-z0-9_\-]+)/([a-z0-9]+)-([a-z0-9_\-]+)-([a-z0-9_\-]+)/index.php?$ 

Now take the hyphens out of the two final groups:

 ^([a-z0-9_\-]+)/([a-z0-9_\-]+)/([a-z0-9]+)-([a-z0-9_]+)-([a-z0-9_]+)/index.php?$ 

See if that works any better.

The final "?" in your pattern makes the last "p" on ".php" optional. That is, the pattern will match "...index.php" or "...index.ph". Is that really what you wanted?

Jim

Zacharias

8:45 am on Aug 14, 2007 (gmt 0)

5+ Year Member



Just wanted to say this worked perfectly.

Thanks again JD Morgan :)

 

Featured Threads

Hot Threads This Week

Hot Threads This Month