views:

37

answers:

1

I have a .htaccess file like this right now. It sends everyone to the index page unless you wanted a real file. This is sort of what I want, but I dont want anyone to be able to access a .php file. So this is what I have:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*) /index.php [NC]

But this is what I want:

if(file_exists(request) && !request.endsWith(".php"))
    do not redirect request
else
    redirect to index page

This is what I tried:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule !(\.php)$ /index.php [NC]

But if i type in the real location of a php file, it still tries to load it. I can always add a few lines to the top of every single php file asking what PHP_SELF is. If PHP_SELF isnt index.php, then I redirect them to the index page. But i think .htacess can do this better.

A: 

i think you need tolook at a custom 404 (file not found) redirect rather than checking if file exists

Haroldo
What asdas is saying is the php files exist so a 404 would not work for those. He just does not want the server to run it and send the response with data.hissite.com/filenothere.htm -> redirect to index.phphissite.com/imporantfile.php -> redirect to index.phpinporantfile.php is there but he does not want it to run.
mjboggess