.htaccess - How to block files from access by URL -
i have subpage like
mypage.com/subpage
but alias , files in/data/subpage
. , file needed accessed user himself index.php
, other files imported index itself, depending on attributes (get, sessions etc.)
i want this:
- let user access
index.php
using/subpage
not/data/subpage
- do not let user directly access in
/data/subpage
, subfolders - still let
index.php
access files.
i hope wrote understandably.
thank help
edit: current .htaccess (located in root)
rewriteengine on rewriterule ^subpage$ /data/subpage/index.php [l] rewriterule ^subpage/(?:([^/]+)/?|)(?:([^/]+)/?|)$ /data/subpage/index.php?section=$1&subsection=$2 [l] rewriterule ^edit/subpage/?(?:([^/]+)/?|)(?:([^/]+)/?|)$ /data/subpage/index.php?edit=true§ion=$1&subsection=$2 [l]
try:
rewritecond %{the_request} \ /+data/subpage/ rewriterule ^ - [l,r=404]
so direct requests /data/subpage/
results in 404. can replace r=404
f
if rather result in "403".
edit:
it's kinda right, thank you. i, viewer, can't access files page cant access (for ex. images). there way it?
this isn't page accessing files, it's page telling browser access them. means way you're going know page told browser access them check referer. unfortunately, referer can trivially forged no guarantee people can't files.
rewritecond %{the_request} \ /+data/subpage/ rewritecond %{http_referer} !^http://yourdomain.com/subpage/(index\.php)? rewriterule ^ - [l,r=404]
Comments
Post a Comment