I have a few problems with my mod_rewrite rules. There a three different url pattern I want to handle.
- http://example.com/%module%/%view%-%args%.html
- http://example.com/%module%/%view%.html
- http://example.com/%module%
The following mod_rewrite rules don’t really work. Also I’ve the problem that the query (example: user.html?foo=bar) doesn’t have an effect.
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^([0-9A-Za-z_-]*)/?([0-9A-Za-z_]+)-?([0-9A-Za-z_,]*)\.html$ index.php?__module=$1&__view=$2&__argv=$3 RewriteRule ^([0-9A-Za-z_-]*)/?$ index.php?__module=$1&__view=&__argv= </IfModule>
For the query string, flag your rules with QSA (Query String Append).
What you are trying to configure is called a ‘front controller’, of which there are already quite a lot ready-made. Maybe you should have a look at some popular PHP frameworks and adopt one that suits you.