View Full Version : rewrite url to remove php extension question

04-28-2009, 11:40 PM

I have loads of files with .php extensions. I would like help writing a mod rewrite rule that will remove the .php extension from urls like this:


I need to retain the "mypage" and pass that on to a controller somehow.


But here is the catch... I don't want the url to show view.php?page=mypage, but I still want somehow for the view.php file to be loaded with that parameter.

Can I combine rewrite rules. One to remove the extension, one to pass the parameter to the view.php file, and one to change the url to finally be something like this:


Any ideas?

04-29-2009, 12:31 AM
Never mind the code below... I thought I had it working but it isn't.

I need the php extension dropped and then the rest of the filename passed on to view.php as a parameter.

This doesnt work:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^([^/\.]+)/?$ view.php?id=$1 [L]