0

I have a module directory in my project and I want to prevent access to PHP files inside it. Besides I have some css and js files in that directory that should be parsed. I used this code in .htaccess

deny from all 

But it made my css and js files not accessible too. How can I prevent access to just PHP files, but not css and js files?

2 Answers 2

1

I've checked @xbonez code and it gives me the same error.

I'm using this code (tested):

Options -Indexes RewriteEngine on RewriteCond %{REQUEST_URI} !\.(css|js)$ [NC] RewriteRule .+ - [F,L] 

Remember to set Options -Indexes so that your folders are not browseable.

Edit:

Notes:
* this code must be put into an .htaccess file and place it inside your desired directory
* %{REQUEST_URI} = the relative url of what you have requested. Example: directory/style.css
* !\.(css|js)$ = every file that doesn't end with css or js
* .+ - [F,L] = forbid the requested url/file

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @machineaddict, I solved it by removing the star. the code should be : <FilesMatch "\.(css|js)$">
0

After the deny for all, you can allow access to css and js files with this directive

<FilesMatch "*\.(css|js)$"> Order Allow,Deny Allow from all </FilesMatch> 

Your final htaccess should look somewhat like this:

Order Deny,Allow Deny from all <FilesMatch "*\.(css|js)$"> Order Allow,Deny Allow from all </FilesMatch> 

1 Comment

Thank you xbonez, I used your code, but it still doesn't parse js and css files. Now in "view srouce" mode when I click on js and css files it gives me "Server Error!" error 500

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.