开发者

Get .htaccess from root directory to apply on all directories?

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]

There are also .htaccess files in subfolders und folders of subfolders, but开发者_如何学C 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.

Thanks in advance for your answers!


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

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.

Rules inherited from the parent scope are applied after rules specified in the child scope.

http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriteoptions


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜