Welcome to WebmasterWorld Guest from 54.160.177.33

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Problem with using only hyphens in rule

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

New User

10+ Year Member

joined:Dec 5, 2005
posts:31
votes: 0


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?

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

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


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.

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

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 0


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

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

New User

10+ Year Member

joined:Dec 5, 2005
posts:31
votes: 0


Just wanted to say this worked perfectly.

Thanks again JD Morgan :)