0

I want to block HTTP access to every file in my project directory except PHP scripts located in the root folder (not subfolders).

My current .htaccess file looks like this :

# Disable Directory Listings in this Directory and Subdirectories
# This will hide the files from the public unless they know direct URLs
Options -Indexes

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^api/(.*)$ api.php/$1 [QSA,L]
</IfModule>

# Deny all files from being accessed with Apache
Order Deny,Allow
Deny from all

# Allow specific PHP files at root
<FilesMatch "/(api|cron|status)\.php$">
    Order Allow,Deny
    Allow from all
</FilesMatch>

This mostly works, except for the URL rewriting on the api.php script. I've tried changing the FilesMatch regexp to /(api|cron|status)(\.php)?$, but it keeps on throwing me a 403 response.

Anyone can explain to me what I did wrong here ? I'm usually OK with regexp, but this has got me thinking Apache doesn't process them like everyone else...

1 Answer 1

1
Deny from all    

<FilesMatch "^(api|cron|status)\.php$">
 Order Allow,Deny
 Allow from all
</FilesMatch>

And I guess make sure your .htaccess is on the root level.

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

1 Comment

Thanks it did the trick. I guess it was the leading slash causing the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.