Mobile app version of vmapp.org
Login or Join
Kevin317

: Restrict direct folder access via .htaccess except via specific links I want to restrict access to a folder on my server so that visitors may only access the contents (a web application) via

@Kevin317

Posted in: #Apache #Htaccess

I want to restrict access to a folder on my server so that visitors may only access the contents (a web application) via links in the same domain. Can I do this using .htaccess? To be clear, I simply want to prevent direct access to the contents so that visitors are routed through other pages on my website in order to get there.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Kevin317

1 Comments

Sorted by latest first Latest Oldest Best

 

@Murphy175

I think something like this might work:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://([-a-z0-9]+.)?YOURDOMAIN.com [NC]
RewriteCond %{REQUEST_URI} ^/PROTECTEDFOLDER/.*$ [NC]
RewriteRule ^(.*)$ "http://www.YOURDOMAIN.com/" [R=301]


I'm haven't tried this, but it should work. Some explanation:


If the referrer is not from your domain, or a subdomain...
If the folder "PROTECTEDFOLDER" is being accessed...
Redirect to your homepage.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme