views:

112

answers:

1

I have a few problems with my mod_rewrite rules. There a three different url pattern I want to handle.

  1. http://example.com/%module%/%view%-%args%.html
  2. http://example.com/%module%/%view%.html
  3. 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>
+3  A: 

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.

PW
I'm working on a PHP5 framework, because I like programming and the aspect of learning by doing. If you are interested: http://code.google.com/p/quail/. I want to keep it simple.
polyurethan