troubleshooting Question

how to prevent direct http requests via .htaccess

Avatar of andy7789
andy7789 asked on
PHPApache Web ServerASP.NET
7 Comments1 Solution739 ViewsLast Modified:
Hi X-perts,

I need to protect a few directories from direct http requests. Currently, I have the following .htaccess file in those directories:

<Files *.php>
Order Deny,Allow
Deny from all

It prevents from executing any php or asp files, but not from viewing .css or .js files. How can I protect those directories from viewing files?

I tried also:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?*$ [NC]
RewriteRule \.(gif|jpg|js|css)$ - [F]

<Files *.php,*.css,*.js>
Order Deny,Allow
Deny from all

But it does not work.

Please, advise.



Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros