Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite

         

jayer

5:57 pm on Feb 6, 2009 (gmt 0)

10+ Year Member



What am I doing wrong here?

I have 4 mod rewrite statements:

RewriteRule ^TLA/([0-9]+)/index.htm$ TLA/index.php?league=$1
RewriteRule ^TLA/([0-9]+)/(.+)/index\.htm$ TLA/index.php?league=$1&team=$2
RewriteRule ^TLA/([0-9]+)/(.+)/([0-9]+)/index\.htm$ TLA/index.php?league=$1&team=$2&category=$3
RewriteRule ^TLA/([0-9]+)/(.+)/(.+)/(.+)\.htm$ TLA/index.php?league=$1&team=$2&category=$3&product=$4

http://www.example.com/1/index.htm
http://www.example.com/1/ALA/index.htm
http://www.example.com/1/ALA/2/3.htm

All work meaning the $_GET variables are matched up correctly.

However,

http://www.example.com/1/ALA/2/index.htm

Does not work. It registers the $_GET['team'] variable as ALA/2 and no $_GET['category'] variable as opposed to registered the $_GET['team'] variable as ALA and the $_GET['category'] variable as 2.

I don't understand why the transition from my first to second rewrite statement would work, but not the transition from the 2nd to 3rd.

Please help. Thanks in advance!

g1smd

7:03 pm on Feb 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The (.+) matches "everything" including multiple slashes, so the rules after number two will never be run.

That is, the (.+) "consumes" everything up to the index part.

Three things to do:

- Add

[L]
to the end of every rule.
- Change
(.+)
to
([^/]+)
or similar (except for the very last one in the very last rule which should be
([^\.]+)
instead).
- Sort the rules from most specific to least specific (reverse of what you have now).

jayer

7:19 pm on Feb 6, 2009 (gmt 0)

10+ Year Member



Thank you! All but the most specific to least specific fixed it. I appreciate the help.

g1smd

7:33 pm on Feb 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It might "fix it" but you do need to do both of the other things too.

There are other problems waiting to catch you out if you don't do them.