问题
I've multiple domain hosting account and so I've hosted multiple domains on that. So I want to separate those with the main domain.
Main hosting : https://example.com
Other hosted website : https://mydomain1.com, https://mydomain2.com
Other hosted websites are under path
https://example.com/domains/mydomain1
https://example.com/domains/mydomain2
So anyone can access the other domain using the above mentioned paths(if he knows) So to separate all domains I want if anyone accessing the domains using the path it should display error message like 404 or 403
But I don't want anyone to access using such path instead he/she can use the actual domain name to access.
Any suggestion appreciated.
PS: I've htaccess file in my other domain to redirect http request to https
RewriteCond %{HTTPS} off
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
Is there any other way to achieve both. redirection to https and above query.
Thanks
回答1:
Inside mydomain1/.htaccess
and mydomain2/.htaccess
have this rule as your very first rule:
RewriteEngine On
# show forbidden for main domain
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteRule ^ - [F]
来源:https://stackoverflow.com/questions/48539144/stop-accessing-my-domain-using-htaccess