Reputation: 53198
I ran into some strange behaviour using mod_rewrite
under Apache. Here's how the current RewriteRules
look:
RewriteRule ^(.*)/collections/(.*)/(.*)/?$ bootstrap.php?controller=category&user=$1&collection=$2&category=$3 [L]
RewriteRule ^(.*)/collections/(.*)/?$ bootstrap.php?controller=collection&user=$1&collection=$2 [L]
My expectations of the above rules is that accessing a URL such as domain.com/BenM/collections/0/1/
should take me to the category
controller, while domain.com/BenM/collections/0/
should take me to the collection
controller.
At the moment, both URL structures rewrite to bootstrap.php?controller=category...
.
My understanding was that if the [L]
flag is specified, Apache looks no further and performs the rewrite.
Could anyone point in the right direction here, as I just cannot beat this... What should the rewrites look like to achieve the functionality I explained above?
Upvotes: 0
Views: 25
Reputation: 78413
You're dealing with greediness-related issues. Also, you probably want a length of at least one, and you almost certainly don't want slashes in your params.
Potential solution:
^([^/]+)/collections/([^/]+)/([^/]+)/?$
^([^/]+)/collections/([^/]+)/?$
Upvotes: 1