Reputation: 2633
This is the rewrite rule I currently use for my MVC application:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)(/([^/]+))?$ application/controller/$1.php?method=$2¶m=$4
Displays as: www.website.com/controller/method/param
The param URI is optional. How would I make method optional as well, so it will allow the user to go to www.website.com/controller?
Could I also additionally force the url to have a trailing slash?
Upvotes: 0
Views: 405
Reputation: 143946
Try:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)(?:/([^/]+)|)(?:/([^/]+)|) application/controller/$1.php?method=$2¶m=$3 [L]
The (?:/([^/]+)|)
are optional capture groups that allows for a "nothing" using the |
symbol.
Upvotes: 2