0

iam creating a php website and iam using htaccess to hide php extensions with this script

  Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]

so if i access localhost/mypage.php or localhost/mypage both will redirect me to mypage.php i want if i accessed it from /mypage.php then redirect me to my page not found page i mean that the user must access it from localhost/mypage only any ideas ??

ArsanGamal
  • 158
  • 1
  • 10

2 Answers2

0

If you want to return a 404 error code and force any PHP request to an error document

RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule \.php$ - [R=404,L]
ErrorDocument 404 /error_404.html

This returns a 404 error code for all *.php requests and shows /error_404.html. The RewriteCond is there to prevent an error code for the already rewritten pages.

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
0

have you thought of using a framework like Zend? My suggestions is more complex i know but....

1) the framework will help you a lot on developing. 2) you will be able to set up all type of routes. 3) there will be no .php extensions. 4) the .htaccess will be really easy to maintain, you will use the standard one of the framework.

Thanks.

an_animal
  • 86
  • 6