[英]Apache2 configuration causing redirect loop
我正在嘗試將我的網站設置為僅使用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網站。
有人能看到配置有問題嗎? 如果沒有,如何縮小原因?
對於非www,您不需要單獨的VirtualHost
條目,而可以使用ServerAlias。 也可以使用以下規則重定向到www:
<VirtualHost *:80>
ServerName www.mydomain.com
ServerAlias 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
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.