Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在子域重定向后禁用与htaccess的直接链接?_Php_Apache_.htaccess_Redirect_Mod Rewrite - Fatal编程技术网

Php 如何在子域重定向后禁用与htaccess的直接链接?

Php 如何在子域重定向后禁用与htaccess的直接链接?,php,apache,.htaccess,redirect,mod-rewrite,Php,Apache,.htaccess,Redirect,Mod Rewrite,我有一个子域名重定向到一个特定的目录地址。如果直接访问,如何禁用该目录地址 i、 e.sub.domain.com重定向到domain.com/sub。当我直接访问domain.com/sub时,它应该重定向到错误404 感谢您在文档根目录中的htaccess中添加以下内容: RewriteEngine on RewriteCond %{HTTP_HOST} !^sub.domain.com$ RewriteRule ^folder - [R=404,L] 如果请求的主机不是sub.doma

我有一个子域名重定向到一个特定的目录地址。如果直接访问,如何禁用该目录地址

i、 e.
sub.domain.com
重定向到
domain.com/sub
。当我直接访问domain.com/sub时,它应该重定向到错误404


感谢您在文档根目录中的htaccess中添加以下内容:

RewriteEngine on

RewriteCond %{HTTP_HOST} !^sub.domain.com$
RewriteRule ^folder - [R=404,L]
如果请求的主机不是sub.domain.com,这将把所有以/folder开头的请求重定向到404页

当我直接访问domain.com/sub时,它应该重定向到错误404

您可以将此规则用作
sub/.htaccess
中的第一条规则:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^sub\. [NC]
RewriteRule ^ - [L,R=404]