子域与htaccess的工作不正常 [英] Subdomains with htaccess not working as expected
问题描述
我知道这是一个非常高度讨论的话题,但我想不出我在做什么错用我的搜索技巧。
I know this is a very highly discussed topic, but I can't figure out what I'm doing wrong using my search skills.
通过下面的文件夹结构,两者的根 domain.local
和 board.domain.local
With the following folder structure as root of both domain.local
and board.domain.local
/
app/
bin/
board/
index.php
src/
vendor/
web/
index.php
和本的.htaccess中的 /
文件夹
And this .htaccess in the /
folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^board.domain.local$
RewriteRule ^(.*)$ board/$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^domain.local$
RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>
访问 board.domain.local
时,我得到一个内部服务器错误。访问 domain.local
完美的作品,并查询重定向到网络/
。
I get an internal server error when accessing board.domain.local
. Accessing domain.local
works perfectly and redirects the queries to web/
.
为什么第一次重写无法正常工作?
Why does the first rewrite not work?
推荐答案
您正在做的相对路径改写每个目录范围内无的RewriteBase
。为什么一个人的作品,但其他没有是由于一些补偿因素在其他地方是网站
之间的不一致。内部服务器错误可能是一个循环。检查你的错误日志。
You're doing relative path rewrites in a per-directory context without RewriteBase
. Why one works but the other doesn't is due to some compensating factor elsewhere which is inconsistent between board
and web
. The internal server error is likely a loop. Check your error log.
RewriteEngine On
RewriteBase / # need this sucker
RewriteCond %{HTTP_HOST} ^board.domain.local$
RewriteRule ^(.*)$ board/$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^domain.local$
RewriteRule ^(.*)$ web/$1 [QSA,L]
在每个目录下,重写的文件系统路径,而不是URL的完成。该重写是在路径的只是目录,它被剥离后的部分进行。如果你做一个相对的重写,该目录部分后放回。然后,一个鲁钝的事情发生了:重写被视为一个URL! 的RewriteBase
指定了preFIX穿上重写(而不是天真的恢复路径preFIX),使之成为有效的URL。 的RewriteBase
说,虽然我们正在处理目录 /无功/网络/文档根目录
,它实际上重新presents的URL空间 /
所以,当从重写重新生成的URL,就应该在那个空间,而不是在 /无功/网络/文档根目录
这是不是一个网址。
In a per-directory context, rewrites are done on file system paths, not URL's. The rewrites are done on just the part of the path after the directory, which is stripped off. If you do a relative rewrite, the directory part is put back after. And then, a moronic thing happens: the rewrite is treated as a URL! RewriteBase
specifies the prefix to put on the rewrite (instead of naively restoring the path prefix) to make it a valid URL. RewriteBase
says, "although we are handling the directory /var/www/docroot
it actually represents the URL space /
so when URLs are re-generated from rewrites, they should be in that space, and not in /var/www/docroot
which is not a URL".
问问自己:什么是文档根
?所以会出现什么URL-S现身相对重写的时候,文档根
被(错误地)被困在为preFIX由于缺少的RewriteBase
?通过配置跟踪那些假网址-S的处理,你一定会发现为什么一个人也陷入一个死循环,而另一个没有。
Ask yourself: what is the DocRoot
? And so what will the URL-s be coming out of the relative rewrite when the DocRoot
is (wrongly) stuck on as a prefix due to the missing RewriteBase
? Trace the handling of those bogus URL-s through your configuration and you will surely discover the reason why one gets into an infinite loop and the other doesn't.
这篇关于子域与htaccess的工作不正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!