prevent执行父文件夹的.htaccess [英] Prevent executing .htaccess of parent folder

查看:173
本文介绍了prevent执行父文件夹的.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好
我有两个不同的网站相同的域例如:
首先在网站根目录下的 http://example.com/
子文件夹中的第二个站点的 http://example.com/site2/
每个网站都有自己的.htaccess
当我进入到第二个站点( http://example.com/site2/ 的),在日志的mod_rewrite我看到阿帕奇试图执行的第一个站点(中的.htaccess的的http:// example.com / 的)。
所以,问题是如何prevent呢? 谢谢

Hello
I have two different sites on same domain for example:
First site in the root directory http://example.com/
Second site in subfolder http://example.com/site2/
Each site have his own .htaccess
When i enter to second site (http://example.com/site2/), in log of mod_rewrite i see that apache trying to execute .htaccess of first site (http://example.com/).
So, the question is how to prevent this? Thanks

推荐答案

虽然你不能停止的.htaccess的 HTTP: //example.com

While you can not stop the execution of the .htaccess in http://example.com

您可以将在其他的.htaccess http://example.com/site2/ 以及任何规则创建在这里,将覆盖在父文件夹的.htaccess中的规则将在这里,但不执行的父文件夹。

You CAN place another .htaccess in http://example.com/site2/ and any rule created here that overrides the rules in the .htaccess of the parent folder will be executed here but not in the parent folder.

例如,我最近有我在那里重写我的主要部位,我们称之为example.com其WWW相当于任何非www版本的情况:www.example.com

For example, I recently had a case where I was rewriting any non-www version of my main site, which we'll call example.com to its www equivalent: www.example.com

这导致的问题是任何人都去我的第二个站点,我们称之为site2.com实际上将用户重定向即使用户输入site2.com或www来www.example.com/site2.com/~~V。 site2.com或 http://www.site2.com 在其浏览器的地址输入

The problem this caused is anyone going to my second site, which we'll call site2.com would actually redirect the user to www.example.com/site2.com/ even if the user enters site2.com OR www.site2.com OR http://www.site2.com in their browser's address input

我必须做些什么来解决它使得变化2 .htaccess文件,第一根 HTTP:// WWW .example.com的然后在一个单独的.htaccess位于 HTTP://www.example。 COM / site2.com /

What I had to do to fix it is makes changes in 2 .htaccess files, first in the root http://www.example.com then in a separate .htaccess located in http://www.example.com/site2.com/

1) http://www.example.com 的.htaccess:

1) http://www.example.com .htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

2) http://www.site2.com (http://www.example.com/ site2.com/)的.htaccess(这也迫使site2.com的WWW版本):

2) http://www.site2.com (http://www.example.com/site2.com/) .htaccess(this also forces the www version of site2.com):

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.site2\.com$ [NC]
RewriteRule ^(.*)$ http://www.site2.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^site2\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com/site2\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.site2\.example\.com$
RewriteRule ^/?$ "http\:\/\/www\.site2\.com\/" [R=301,L]

随意撕开我的正则表达式,我绝不是一个正则表达式高手。我也意识到,这可能造成2或者更多额外的重定向,但是这是我能得到这个工作的唯一途径,而无需通过通过主机...这可能是一个更好的选择,如果你的主机能做到这一点重新分配我的DocumentRoot,该矿将/不能......

Feel free to rip apart my regex, I am by no means a regex master. I also realize that this can creates 2 or maybe more extra redirects but this is the only way I could get this to work, without reassigning my DocumentRoot through through the host...which is probably a better option if your host can do it, mine would/could not...

这篇关于prevent执行父文件夹的.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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