Apache:如何避免对位于domain.com DocumentRoot 下的sub.domain.com 进行domain.com/.htaccess 规则?
如何避免对位于domain.com DocumentRoot
下的sub.domain.com 的domain.com/.htaccess 规则?
- domain.com
DocumentRoot /domain
- sub.domain.com
DocumentRoot /domain/sub
- dir /domain/.htaccess :
重定向 301 / art http://domain.com/article/art
- 目录下没有 .htaccess /domain/sub
如果只有domain.com有这个规则,为什么sub.domain.com/art也有301重定向到domain.com/article/art?
这可能是 XAMPP 1.7.4 的错误吗?
更新:它也不起作用(sub.domain.com/art 仍然返回 301 重定向到 domain.com/article /艺术):
<VirtualHost *:80>
DocumentRoot /domain
ServerName domain.com
<Directory />
AllowOverride None
</Directory>
<Directory /domain>
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /domain/sub
ServerName sub.domain.com
<Directory />
AllowOverride None
</Directory>
<Directory /domain/sub>
</Directory>
</VirtualHost>
How to avoid domain.com/.htaccess rules to sub.domain.com that is located under domain.com DocumentRoot
?
- domain.com
DocumentRoot /domain
- sub.domain.com
DocumentRoot /domain/sub
- dir /domain/.htaccess :
Redirect 301 /art http://domain.com/article/art
- no .htaccess under dir /domain/sub
Why also sub.domain.com/art has 301 redirect to domain.com/article/art, if just domain.com has this rules?
Is it maybe some XAMPP 1.7.4 bug?
Update: It does not work with it either (sub.domain.com/art still returns 301 redirect to domain.com/article/art):
<VirtualHost *:80>
DocumentRoot /domain
ServerName domain.com
<Directory />
AllowOverride None
</Directory>
<Directory /domain>
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /domain/sub
ServerName sub.domain.com
<Directory />
AllowOverride None
</Directory>
<Directory /domain/sub>
</Directory>
</VirtualHost>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是避免使用 .htaccess 并使用虚拟主机。
一台用于domain.com 的虚拟主机。
subdomain.com 的一个虚拟主机。
在每个 VirtualHost 中,您可以为第一个 VirtualHost 定义
和
,以及
code> 和
用于第二个。然后删除所有 .htaccess 或在
中使用 AllowOverride None (效果相同)。您还会看到,当 apache 不必检查所有父目录中是否存在 .htaccess 时,它会更快。所有目录指令都可以包含与您通常在 .htaccess 中使用的内容完全相同的内容。 .htaccess 是一种当你不希望某人编辑 apache 配置文件时让某人定义一些目录指令的方法;但 .htaccess 文件是为了与目录树继承相关。
One way is to avoid using .htaccess and use virtualhosts.
One VirtualHost for domain.com.
One VirtualHost for subdomain.com.
inside each VirtualHost you can define
<Directory />
and<Directory /domain>
for the first one, and<Directory />
and<Directory /domain/sub>
for the second one. Then remove all .htaccess or use AllowOverride None in the<Directory />
(same effect). You'll see as well that apache is faster when he doesn't have to check for existence of .htaccess in all parent directories.All Directory instructions can contains exactly the same thing as what you usually use in .htaccess. .htaccess is a way to let someone define some Directory instructions when you don't want him to edit apache configuration files; But .htaccess files are done to be related with directory tree inheritance.