请求包含父文件夹时的htaccess限制访问权限

时间:2015-01-17 03:50:54

标签: .htaccess subdomain

如果网站位于共享主机位,父文件夹和子文件夹位于子文件夹中,是否可以在网址请求包含父域时限制对子域的访问?

共享托管空间中的文件夹结构是:

domain.com     等等     这个     那     subdomaina.com

我可以访问子域名     a)http://subdomaina.com     b)http://domain.com/subdomaina.com

如何防止b发生?

我在domain.com中添加了一个.htaccess文件,其中301重定向到http://subdomaina.com,但是我得到了一个像http://subdomaina.com/index.php/index.php/index.php这样的循环......

2 个答案:

答案 0 :(得分:0)

听起来您的网站没有正确设置和配置。

  

是否可以在url请求包含时限制对子域的访问   父域?

是的,在正常DNS - >下webserver virtual host - > source files (index.html etc)配置 - 对父域及其内容的请求与子域分开 换句话说,子域实际上与完全不同的网站的处理方式相同。

  

如何防止b发生?

您需要将您的网络服务器配置为将对子域的请求路由到文件系统上的单独文件夹。 (即document root)。 您的服务器共享这一事实与您配置和组织文件等的方式没有实际区别

所以你应该拥有的是

request for                              
subdomaina.com --->|             |--->subdomaina.com - content files
                   |             |   /home/web/subdomaina/index.html
                   |-->webhost --|
                   |   server    |     
request for ------>|             |---> domaina.com - content files
 domaina.com       |             |   /home/web/subdomaina/index.html

您的网络服务器配置“知道”哪个文件属于哪个域。

你是如何设置的?

如果您有共享托管服务 - 通常您只需致电或发送技术支持,并要求他们帮助您设置子域名。
否则你可以自己做 - 通常是通过cpanel 您需要在哪里指定子域以及子域的文件所在的位置。

答案 1 :(得分:0)

  

我可以访问子域a,例如a)http://subdomaina.com b)http://domain.com/subdomaina.com如何防止b发生?

您可以在subdomaina.com/.htaccess文件中使用此代码:

RewriteEngine On

# forbid access is domain is not subdomaina.com
RewriteCond %{HTTP_HOST} !^(www\.)?subdomaina\.com$ [NC]
RewriteRule ^ - [F]
相关问题