Prettifying URLs for a PHP-based club website I have a website for my car enthusiast club ("example.org") whose content can be divided into three main sections: Startseite (the "front page" of the site), Mitglieder (membership directory), and Vereinsinfos ("about us").  For each section, the content is handled by a corresponding PHP script: /home.php, /mitglieder.php, and /verein.php.

I'd like to prettify the URLs to eliminate the .php extensions, so that the URLs look like


http://example.org/home (maps to /home.php)
http://example.org/home/ (also maps to /home.php)
http://example.org/home/1 (maps to /home.php with a data=1 query string)


After reading all documentation, I formed my .htaccess like this (repeated for the mitglieder and verein sections):

RewriteRule ^home\/$ /home.php [L]
RewriteRule ^home$ /home/ [L]
RewriteRule ^home\/([^/]*)$ /home.php?data=$1 [L]


This works, but I can't figure out how to improve it further after reading all the documentation on the Internet.  (I have difficulty understanding regular expressions.)

In addition to the content above, I also have static resources under /images/, /js/, /css/, etc. which should be left alone.
You can combine these:

RewriteRule ^home\/$ /home.php [L]
RewriteRule ^home$ /home/ [L]


Into:

RewriteRule ^home\/?$ /home.php [L]


In addition, you should also map /home.php to /home.
So this will do all three:

RewriteRule ^home(?:\/|\.php)?$ /home.php [L]


Now your /home/1 rules. You've already got it, but you can make slight improvement:

RewriteRule ^home\/([^/]+)$ /home.php?data=$1 [L]


The + differentiates this rule from /home/.

If the data is alphanumerical you can improve this further:

RewriteRule ^home\/([\w-]+)$ /home.php?data=$1 [L]


You can replace home with other URLs
as well.