我的根目录(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应用于所有目录?
发布评论