homepage Welcome to WebmasterWorld Guest from 54.234.60.133
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
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




msg:3417713
 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




msg:3418025
 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




msg:3418088
 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




msg:3421539
 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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved