What is .htaccess RewriteRule best practice?
Posted
by Pablo
on Stack Overflow
See other posts from Stack Overflow
or by Pablo
Published on 2010-05-20T00:09:35Z
Indexed on
2010/05/20
0:10 UTC
Read the original article
Hit count: 296
Is it better to have a single RewriteRule with a bunch of RegEx or multiples Rules with fewer RegEx for the server to query? Will there be any performance differences?
Heres is an example a single rule with almost all RegEx groups as optional:
RewriteRule ^gallery/?([\w]+)?/?([\w]+)?/?([\d]+)?/?([\w]+)/?$ /gallery.php?$1=$2&start=$3&by=$4 [NC]
Here are some of the rules lists that would replace the one above:
RewriteRule ^gallery/category/([\w]+)/$ /gallery.php?category=$1& [NC]
RewriteRule ^gallery/category/([\w]+)/([\d]+)/$ /gallery.php?category=$1&start=$2 [NC]
RewriteRule ^gallery/category/([\w]+)/([\d]+)/([\w]+)/$ /gallery.php?category=$1&start=$2&by=$3 [NC]
...
RewriteRule ^gallery/tag/([\w]+)/$ /gallery.php?category=$1& [NC]
RewriteRule ^gallery/tag/([\w]+)/([\d]+)/$ /gallery.php?category=$1&start=$2 [NC]
RewriteRule ^gallery/tag/([\w]+)/([\d]+)/([\w]+)/$ /gallery.php?category=$1&start=$2&by=$3 [NC]
...
I'll be glad to hear your options or personal experiences.
© Stack Overflow or respective owner