从根目录获取.htaccess应用于所有目录?

编程入门 行业动态 更新时间:2024-10-25 20:19:22
本文介绍了从根目录获取.htaccess应用于所有目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的根目录(public_html /)中有一个.htaccess文件,如下所示:(XXX.XX.XX.XX代表IP)

i have a .htaccess file in my root directory (public_html/) that looks like this: (XXX.XX.XX.XX stands for an IP)

RewriteCond %{HTTP_HOST} ^XXX.XX.XX.XX$ [NC] RewriteRule ^(.*)$ www.justadomain.tld [R=301,L]

子文件夹和子文件夹中也有.htaccess文件,但我要重写规则可以在帐户的所有目录中工作(无论是否存在.htaccess),而无需在每个文件中都复制此规则。现有的.htaccess文件中的规则应继续起作用。

There are also .htaccess files in subfolders und folders of subfolders, but I want this rewrite rule to work in all directories all over the account whether there exists a .htaccess or not, without copying this rule in every single file. The rules in the existing .htaccess files should continue working.

在此先感谢您的回答!

推荐答案

如果还希望从父.htaccess重写规则,还需要在子文件夹的每个.htaccess中添加以下行:

You need to add the following line into each .htaccess in subfolders if you want to have rewrite rules from parent .htaccess to be executed as well:

RewriteOptions inherit

这将强制当前配置继承父级的配置。在每个虚拟服务器上下文中,这意味着继承了主服务器的映射,条件和规则。在每个目录上下文中,这意味着父目录的.htaccess配置的条件和规则是继承的。

This forces the current configuration to inherit the configuration of the parent. In per-virtual-server context, this means that the maps, conditions and rules of the main server are inherited. In per-directory context this means that conditions and rules of the parent directory's .htaccess configuration are inherited.

规则从父作用域将在子作用域中指定的规则之后应用。

httpd.apache/docs/current/mod/mod_rewrite.html#rewriteoptions

或者-将您的全局规则从.htaccess移到 VirtualHost上下文中(当然,前提是您只能编辑服务器配置文件)。

Alternatively -- move your "global" rule(s) from .htaccess into VirtualHost context (that's only if you can edit server config files, of course).

更多推荐

从根目录获取.htaccess应用于所有目录?

本文发布于:2023-11-01 23:01:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550659.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:根目录   应用于   目录   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!