如何使用.htaccess禁止访问子域?

时间:2017-09-29 07:33:19

标签: php apache .htaccess redirect mod-rewrite

我使用这家网络托管公司认为提供网络访问我的电子邮件设置将是一个好主意"。所以基本上如果我的网站是example.com,像http://mailboxes.example.com这样的网址会打开一个登录页面。所以我想知道是否有办法通过mailboxes禁用.htaccess子域内的任何内容? (或者可能重定向它。)

到目前为止,我尝试进行重定向:

# Prevent webmail access
RewriteCond %{HTTP_HOST} ^mailboxes\.example\.com$   [NC]
RewriteRule ^ http://example.com/contactme  [L,R]

但这似乎没有做任何事情,页面仍在加载。

编辑:伙计们,这里有完整的.htaccess文件,以防万一:

RewriteEngine on

# Define priority of which index file is used first
DirectoryIndex index.php index.htm index.html

# Error pages:
ErrorDocument 401 /err401.php
ErrorDocument 403 /err403.php
ErrorDocument 404 /err404.php
ErrorDocument 500 /err500.php

# Prevent opening directory listings from the web
Options -Indexes

# Prevent 'error_log' from being accessed from the web:
RewriteRule (^|/)error_log$ - [L,R=404]

# Redirect access to mailboxes subdomain
RewriteCond %{HTTP_HOST} ^mailboxes\.example\.com$   [NC]
RewriteRule ^ http://example.com/contactme/  [L,R]

# Prevent .ini and other files from being open from web browser
<filesMatch ".*\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
 Order Allow,Deny
 Deny from all
</filesMatch>

<filesMatch "phprc$">
 Order Allow,Deny
 Deny from all
</filesMatch>

0 个答案:

没有答案