Forum Moderators: phranque
is what I am using.
I see 2 problems, 1) is resources, I have been told * is a hog. And 2) it seems that the middle rule overpowers the end rule when they both match. Just not sure how to resolve this.
Any suggestions would be awesome :)
RewriteCond %{REQUEST_URI} !/index\.php$
RewriteRule ^([^/]+)/([^/]+)/(.+)/?$ index.php?year=$1&team=$2&game=$3 [L]
#
RewriteCond %{REQUEST_URI} !/index\.php$
RewriteRule ^([^/]+)/(.+)/?$ index.php?year=$1&team=$2 [L]
#
RewriteCond %{REQUEST_URI} !/index\.php$
RewriteRule ^(.+)/?$ index.php?year=$1 [L]
The rules were also reversed in order.
If index.php is a single file in the Web root directory, then you can make the rules even more efficient by using:
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^([^/]+)/([^/]+)/(.+)/?$ /index.php?year=$1&team=$2&game=$3 [L]
#
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^([^/]+)/(.+)/?$ /index.php?year=$1&team=$2 [L]
#
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^(.+)/?$ /index.php?year=$1 [L]
I assume this code goes into .htaccess. If not, it will need some adjustements to run in httpd.conf.
Note that a RewriteCond only affects the single RewriteRule that immediately follows it.
Use [L] on all rules unless you know a reason not to.
Never use ".*" or ".+" in a pattern when it can be avoided. They are "easy," but very inefficient when used as the initial subpatterns in patterns with multiple subpatterns. I.e. It's OK to use them at the end of a pattern, but not at the beginning or in the middle.
Just for reference "[^/]+" means, "Match one or more characters except for slash," or more practically in this case, "Match all characters up to the next slash."
The "/?" at the end of each pattern will allow, but not require, a trailing slash.
See the documentation cited in our forum charter for more info.
Jim