apache - How to forbid HTTP access to PHP files? -


i'm trying rewrite urls using mod_rewrite. rewrite rule in .htaccess file:

rewriterule ^([a-z]+)/?$ $1\.php 

if user inputs example.com/contact, contents of example.com/contact.php file load.

the problem is, leaves me duplicate content because both example.com/contact , example.com/contact.php display same information.

i'd forbid access php files if users attempt access via http allow script access (i need application work). how can using .htaccess?

everything i've tried blocks both script , http access. example, using following in .htaccess forbids http access causes script stop working:

deny 

you can use the_request that.

your code should now

options -multiviews rewriteengine on  # if file exists , has ".php" extension redirect extensionless equivalent rewritecond %{request_filename} -f rewritecond %{the_request} \s/([^/]+)\.php(?:\s|\?) [nc] rewriterule ^ /%1? [r=301,l]  # if uri + ".php" exists internally rewrite "uri.php" rewritecond %{document_root}/$1\.php -f rewriterule ^([^/]+)$ /$1.php [l] 
  • http://example.com/contact.php redirect http://example.com/contact
  • http://example.com/contact internally rewrite /contact.php

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -