Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
如何在.htaccess中阻止对网站主页的访问?_.htaccess - Fatal编程技术网

如何在.htaccess中阻止对网站主页的访问?

如何在.htaccess中阻止对网站主页的访问?,.htaccess,.htaccess,如何在.htaccess中阻止对网站主页的访问? 我可以轻松阻止访问网站的特定子页面,例如domain.com/blog: RedirectMatch 404 ^/blog.*$ 但是,我不知道如何阻止网站的主页:domain.com,因此只有它被阻止,而domain.com/blog子页面可以工作 我尝试在PHP中添加“!”(阻止对除/blog以外的所有页面的访问),但在.htaccess中不起作用 RedirectMatch 404 !^/blog.*$ 有人能帮我吗?我要从中增加以下内

如何在.htaccess中阻止对网站主页的访问? 我可以轻松阻止访问网站的特定子页面,例如domain.com/blog:

RedirectMatch 404 ^/blog.*$
但是,我不知道如何阻止网站的主页:domain.com,因此只有它被阻止,而domain.com/blog子页面可以工作

我尝试在PHP中添加“!”(阻止对除/blog以外的所有页面的访问),但在.htaccess中不起作用

RedirectMatch 404 !^/blog.*$

有人能帮我吗?

我要从中增加以下内容:

试着让它适应你的特定领域。它应该允许subdomain.domain.com并将domain.com重定向到google.com


编辑:包括注释人:
RedirectMatch 404^/$
应该只阻止根目录,而不是其他页面。

你们都是对的

RedirectMatch 404 ^/$
它起作用了! 我不知道为什么,但我以前检查过,它不工作,现在没事了:)

不过,我还有第二个问题:
如何阻止除/blog之外的所有子页面+主页?

只需使用:
重定向匹配404^/$
否,此阻止所有(主页+子页面)。。。我只想屏蔽主页,这是不对的
RedirectMatch 404^/$
仅阻止主页,但不阻止
example.com/subdir/
欢迎使用SO。请看一看和。是的,它是有效的,但是如何阻止除/博客之外的所有子页面+主页?您可以发布您自己问题的答案,但最好将单独的问题作为单独的问题提问。
RedirectMatch 404 ^/$