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
redirecthttp://example.com/contact
http://example.com/contact
internally rewrite/contact.php
Comments
Post a Comment