views:

29

answers:

2

Hi, I did a .htaccess that change urls like www.site.com/sell.php to www.site.com/sell. Sell page exists at my / and it works fine. The problem is when i try something like www.site.com/sadasdasdasdadsdfgfds, because "sadasdasdasdadsdfgfds" doesn't exist. I receive a 500 Apache's error.

This is my .htaccess file:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /$0.php

How could I fix it? Thank you guys.

UPDATE: Worked! Thanks guys! Now how do I redirect user to a 404 custom error page?

A: 

You need to test if the new destination is an existing file:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .* /$0.php

Otherwise you will get an infinite recursion.

Gumbo
+1  A: 

You have checks to make sure the file doesn't exist. You also have to make sure the corresponding php-file does exist:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .* /$0.php
edwin