phpwebdev
phpwebdev

Reputation: 103

How do I use filesmatch in htaccess to restrict access to one folder but allow access to a subdomain of the url?

I am trying to restrict access to a folder called admin, for subdomains www or no subdomain. The following code in htaccess does that.


<FilesMatch "^(admin)">
Order allow,deny
Deny from all
</FilesMatch>

The problem is that it also restricts access to this subdomain, which I do not want.

http://edit.example.org/admin

How do I use filesmatch in htaccess to restrict access to one folder but make an exception for a certain subdomain?

I want to restrict access to http://example.org/admin

but allow access to http://edit.example.org/admin

I am not the best at regular expressions :(

There is a similar question but without a good answer.

According to this regex tester, this should work but does not.

https://www.debuggex.com/r/y5RYSoP8Ug0rmxO1

Upvotes: 1

Views: 212

Answers (1)

anubhava
anubhava

Reputation: 785266

You may be able to do this using mod_rewrite rules in your site root .htaccess:

RewriteEngine On

# block access to /admin for domain example.com  
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^admin(?:/|$) - [F,NC]

Upvotes: 2

Related Questions