从根目录获取.htaccess应用于所有目录? [英] Get .htaccess from root directory to apply on all directories?

查看:62
本文介绍了从根目录获取.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 ^(.*)$ http://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.

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

http://httpd.apache.org/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应用于所有目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆