我正在尝试将我的网站设置为仅使用 www,而非 www 应永久重定向到 www。这个答案建议使用两个虚拟主机,但是它使我进入重定向循环。
这是该站点的配置:
<VirtualHost *:80>
  ServerName  www.mydomain.com
  DirectoryIndex index.html index.php
  DocumentRoot /home/me/sites/mydomain.com/htdocs
  # Log file locations
  LogLevel warn
  ErrorLog  /home/me/sites/mydomain.com/logs/error.log
  CustomLog /home/me/sites/mydomain.com/logs/access.log combined
</VirtualHost>
<VirtualHost *:80>
  ServerName mydomain.com
  Redirect permanent / http://www.mydomain.com/
</VirtualHost>
当我访问该站点的非 www 版本时,它成功重定向到 www 版本,但是 Chrome 然后告诉我有一个重定向循环。
起初我以为它可能.htaccess在我的文档根目录中,但是在删除该文件后它仍然会发生。这只是一个简单的 Wordpress 网站。
任何人都可以看到导致这种情况发生的配置错误吗?如果没有,我该如何缩小原因?