first of all: hi to the forum
I have a kinda weird problem. I'd like to rewrite URLs for a MVC (Model View Controller) based framework and cannot solve this.
The url looks like http://www.domain.tld/controller/action/id and shall be rewritten to http://www.domain.tld/controller.php?a=action&i=id
Additionally all the other possibilities have to work too:
http://www.domain.tld/controller => http://www.domain.tld/controller.php
http://www.domain.tld/controller/ => http://www.domain.tld/controller.php
http://www.domain.tld/controller/action => http://www.domain.tld/controller.php?a=action
http://www.domain.tld/controller/action/ => http://www.domain.tld/controller.php?a=action
What I tried is the following
- Code: Select all
RewriteRule ^([a-zA-Z0-9]+)$ $1.php [L,QSA]
RewriteRule ^([a-zA-Z0-9]+)/$ $1.php [L,QSA]
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9._]+)$ $1.php?action=$2 [L,QSA]
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9._]+)/$ $1.php?action=$2 [L,QSA]
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ $1.php?action=$2&id=$3 [L,QSA]
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/$ $1.php?action=$2&id=$3 [L,QSA]
This works as long as the URL keeps with this pattern.
Is there a possibility to get these rules in only one rule and how can I exclude some folders (like CSS, Javascript) from being rewritten? Do I need a RewriteCondition before every rule?
Hope you can help me.
Thanks a lot.