Minion
Minion

Reputation: 2567

.htaccess prevent folder access that are subdomains

in my webhost every time I create a new subdomain it creates a public-access folder in my html_public folder, and I want to block the access to those folders with a fake 404 error (using the default one if it's possible, I'm using this to set the default 404 error: ErrorDocument 404 /404.php) but allowing to access if it is the subdomain.

For example:

http://www.mydomain.com/blog/ -> Should show a 404 Not found error
http://blog.mydomain.com -> Should allow the user to access

Both of them are the same folder html_public/blog

I tried to add a .htaccess file in blog folder with this code:

order deny,allow
deny from all

But it does not allow the access (logic), it does not matters if it is folder or subdomain.

And this one:

RewriteRule ^blog/* /404.php

But like other, it redirects all to a 404 error, instead of only the direct access to the folder and allowing the access to the subdomain.

Note: I saw other questions that redirects from folder to subdomain, I need to show a 404 error.

Can someone help me? Thanks in advanced.

Upvotes: 1

Views: 3056

Answers (1)

Jon Lin
Jon Lin

Reputation: 143846

Try:

RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^blog/ /404.php [L,R=404]

Upvotes: 3

Related Questions