Stop accessing my domain using htaccess

好久不见. 提交于 2019-12-24 08:38:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!