如何制作Apache .htaccess 404插件域的子域/目录?

cbeh67ev  于 2022-11-16  发布在  Apache
关注(0)|答案(2)|浏览(139)

请原谅我对Apache缺乏经验,但我正在尝试设置我的.htaccess文件,使我的2个插件域的子域和目录无法通过主域访问(即它们将为404)。换句话说,addon-domain-1.primary-domain.comprimary-domain.com/addon-domain-1都应该是不可访问的。
我想我的思路是对的,但是我当前的实现不起作用。

# Redirect to www/https
RewriteEngine on
RewriteCond %{HTTP_HOST} ^primary-domain\.com [NC]
RewriteRule ^(.*)$ https://www.primary-domain.com/$1 [R=301]

# Block addon domain directories
RewriteCond %{HTTP_HOST} ^addon-domain-1\.primary-domain\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^addon-domain-2\.primary-domain\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?primary-domain\.com [NC]
RewriteCond %{REQUEST_URI} ^/addon-domain-1/(.*) [OR]
RewriteCond %{REQUEST_URI} ^/addon-domain-2/(.*)
RewriteRule ^(.*)$ - [R=404,L]

.htaccess文件位于根目录(primary-domain.com)中
非常感谢!

i2byvkas

i2byvkas1#

可以按如下方式设置块规则:

# Block addon domain directories
RewriteCond %{HTTP_HOST} ^((www|addon-domain-1|addon-domain-2)\.)?primary-domain\.com$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/(addon-domain-1|addon-domain-2)/ [NC]
RewriteRule ^ - [F]
xlpyo6sf

xlpyo6sf2#

最后通过做一些类似于@anubhava的回答(有一些变化)来解决这个问题,最重要的是把这些变化也放在插件域的.htaccess文件中。
主要网域:

# Forward to www/HTTPS
RewriteEngine on
RewriteCond %{HTTP_HOST} ^primary-domain\.com [NC]
RewriteRule ^(.*)$ https://www.primary-domain.com/$1 [R=301]

# Block addon domain directories
RewriteCond %{HTTP_HOST} ^(www\.)?(addon-domain-1|addon-domain-2)\.primary-domain\.com [NC,OR]
RewriteCond %{REQUEST_URI} ^/(addon-domain-1|addon-domain-2)
RewriteRule ^(.*)$ - [R=404,L]

加载项域1:

# Forward to www/HTTPS
RewriteEngine on
RewriteCond %{HTTP_HOST} ^addon-domain-1\.com [NC]
RewriteRule ^(.*)$ https://www.addon-domain-1.com/$1 [R=301]

# Block addon domain directories
RewriteCond %{HTTP_HOST} ^(www\.)?addon-domain-1\.primary-domain\.com [NC,OR]
RewriteCond %{REQUEST_URI} ^/addon-domain-1
RewriteRule ^(.*)$ - [R=404,L]

相关问题