Forum Moderators: phranque

Message Too Old, No Replies

htaccess rewrite efficiency

Is there a better way to code this?

         

DustinGreen

9:19 pm on Jul 11, 2007 (gmt 0)

10+ Year Member




System: The following message was cut out of thread at: http://www.webmasterworld.com/apache/3374580.htm [webmasterworld.com] by jdmorgan - 10:01 am on July 12, 2007 (CDT -5)


hey guys and gals, this is my first post/question.

Im just getting the hang of this .htaccess thing and im wondering if there is a smarter way to write this code:

RewriteRule ^([a-zA-Z0-9_\-]+)/index.php?$ index.php?reg=$1
RewriteRule ^([a-zA-Z0-9_\-]+)/([a-zA-Z0-9_\-]+)/index.php?$ index.php?reg=$1&statename_=$2
RewriteRule ^([a-zA-Z0-9_\-]+)/([a-zA-Z0-9_\-]+)/([a-zA-Z0-9_\-]+)/index.php?$ index.php?reg=$1&statename_=$2&city_=$3
RewriteRule ^([a-zA-Z0-9_\-]+)/([a-zA-Z0-9_\-]+)/([a-zA-Z0-9_\-]+)/([a-zA-Z0-9_\-]+)/index.php?$ index.php?reg=$1&statename_=$2&city_=$3&hotelid=$4
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?reg=$1&statename_=$2&city_=$3&hotelid=$4&mod=$5 [L]

jdMorgan

3:52 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Suggestions:

Use the [NC] flag to make pattern-matching case-insensitive. This allows you to use [A-Z] or [a-z] instead of [A-Za-z].

Use the [L] flag on every rule, unless you need to process the output of that rule through a subsequent rule.

Put your rules in order, from most-frequently-matched to least.

Jim

DustinGreen

7:20 pm on Jul 12, 2007 (gmt 0)

10+ Year Member



cool thx that helped