将所有子域发送到状态为404的404目录

时间:2015-03-23 20:15:31

标签: apache .htaccess

我试图让所有子域名转到404页面,但管理员除外:

# MAKE ALL OTHER SUB DOMAINS 404
RewriteCond %{HTTP_HOST} ^\.example\.com$
RewriteRule !^404/? [R=404,L]

# ALLOW ADMIN SUB DOMAIN AND SEND TRAFFIC TO SUB FOLDER
RewriteCond %{HTTP_HOST} ^admin\.example\.com$
RewriteRule !^admin/? admin%{REQUEST_URI} [NC,L]

但是404不起作用(它显示了根内容)......我做错了什么?

它应该设置404的状态,但是通过重写从根目录下的404目录加载内容。

1 个答案:

答案 0 :(得分:1)

这样做:

RewriteEngine On
RewriteBase /

# ALLOW ADMIN SUB DOMAIN AND SEND TRAFFIC TO SUB FOLDER
RewriteCond %{HTTP_HOST} ^admin\.example\.com$ [NC]
RewriteRule !^admin/? admin%{REQUEST_URI} [NC,L]

# MAKE ALL OTHER SUB DOMAINS 404
RewriteCond %{HTTP_HOST} !^(www|admin)\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule !^404/ 404/ [L]