0

This is my .htaccess. It redirects /contact to index.php?page=contact
This works perfectly. But with this .htaccess, if someone puts /contact.php, they'll get an error.

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteRule ^([^/]+)/?$ index.php?page=$1  [QSA]

Basically, is there any way to only rewrite if there's no .php in the URL?
If there's a .php in the URL, e.g. contact.php just load the normal .php page.

How could I do this?

Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
Yannick Bloem
  • 147
  • 2
  • 4
  • 12
  • possible duplicate of [mod\_rewrite to remove .php but still serve the .php file?](http://stackoverflow.com/questions/1698464/mod-rewrite-to-remove-php-but-still-serve-the-php-file) – typeoneerror May 28 '13 at 14:27

1 Answers1

2

Add something like this before the RewriteRule:

RewriteCond %{REQUEST_FILENAME} !-f

-f means "is a file". With this rule you are saying "requested file name is not an existing file" (in the DocumentRoot, ofc).

More info and options: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond