简体   繁体   English

$ _SERVER [HTTP_HOST]的域错误?

[英]Wrong domain with $_SERVER[HTTP_HOST]?

I tried to set up an htaccess file, which simply redirects all urls which are unlike one to another url: 我试图设置一个htaccess文件,该文件只是将所有不同于一个的URL重定向到另一个URL:

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

But i recognized something strange, for some reason it results in an endless loop. 但是我意识到一些奇怪的事情,由于某种原因,它会导致无休止的循环。 So i did some tests. 所以我做了一些测试。

My Webspace looks like this: 我的网络空间看起来像这样:

 -root 
 ---folder 1 
 ---folder 2

And i have 2 Domains, one is targeting the root-folder and the other one is targeting a subfolder: 我有2个域,一个以根文件夹为目标,另一个以子文件夹为目标:

-root <--- http://another-url.com
--- folder 1
--- folder 2 <---- http://www.example.com

I asume that %{HTTP_HOST} from my htaccess file is recognizing every url as the http://another-url.de , which is unlike my www.example.com and so it redirects to www.example.com which of cause results in an endless loop. 我假设htaccess文件中的%{HTTP_HOST}会将每个URL识别为http://another-url.de ,这与我的www.example.com不同,因此它重定向到www.example.com,其原因是无休止的循环。

I did a simple check: I created a PHP File in my folder 2 which prints the $_SERVER[HTTP_HOST] . 我做了一个简单的检查:我在文件夹2中创建了一个PHP文件,其中显示了$_SERVER[HTTP_HOST] Opend the file through http://www.example.com and i got the output www.another-url.com. 通过http://www.example.com打开文件,我得到了输出www.another-url.com。

Does anyone know whats going on? 有人知道发生了什么吗? And how i could solve this?! 而我该如何解决呢?

I know this is an old question, but I had the same issue today in Google Chrome, on a local environment that hosts many fake development domains. 我知道这是一个老问题,但今天在托管许多虚假开发域的本地环境中,我在Google Chrome浏览器中遇到了同样的问题。 Here's what fixed it for me: 这是为我解决的问题:

  • Open the developer tools (Ctrl-Alt-i on PC, Cmd-Option-i on Mac) 打开开发人员工具(在PC上为Ctrl-Alt-i,在Mac上为Cmd-Option-i)
  • Press and hold the refresh button 按住刷新按钮
  • When the options appear, choose Empty Cache and Hard Reload 出现选项时,选择“ Empty Cache and Hard Reload

After that, the correct domain loaded. 之后,将加载正确的域。 So Chrome must have had a bad DNS entry cached or something. 因此,Chrome浏览器肯定缓存了错误的DNS条目或其他内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM