homepage Welcome to WebmasterWorld Guest from 54.197.183.230
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Problem with using only hyphens in rule
Zacharias

5+ Year Member



 
Msg#: 3417711 posted 10:04 am on Aug 9, 2007 (gmt 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?

 

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3417711 posted 4:17 pm on Aug 9, 2007 (gmt 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.

jdMorgan

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



 
Msg#: 3417711 posted 5:26 pm on Aug 9, 2007 (gmt 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

Zacharias

5+ Year Member



 
Msg#: 3417711 posted 8:45 am on Aug 14, 2007 (gmt 0)

Just wanted to say this worked perfectly.

Thanks again JD Morgan :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved