注意:请参阅本文末尾的更新。有关最终(有效)配置文件的信息,请参阅本博文末尾或我标记为解决方案的博文的更新4。
我错误地配置了我的Apache conf文件,现在我遇到了重定向错误(ERR_TOO_MANY_REDIRECTS)。我想将所有内容重定向到HTTPS(非www)。我已经尝试将其添加到有关this tips的wp-config.php中,但这并不能解决问题:
define('WP_HOME','http://d0main.xyz');
define('WP_SITEURL','http://d0main.xyz');
我试图添加
define('WP_HOME','https://d0main.xyz');
define('WP_SITEURL','https://d0main.xyz');
这是我的Apache文件:
d0main.xyz.conf
<VirtualHost *:80>
ServerName d0main.xyz
ServerAlias www.d0main.xyz
ServerAdmin [email protected]
DocumentRoot /var/www/html
Redirect permanent / https://d0main.xyz
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
# changed from None to FileInfo
AllowOverride FileInfo
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
d0main.xyz-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName d0main.xyz
ServerAlias www.d0main.xyz
ServerAdmin [email protected]
DocumentRoot /var/www/html
Redirect permanent / https://d0main.xyz
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
# changed from None to FileInfo
AllowOverride FileInfo
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
SSLCertificateFile /etc/letsencrypt/live/d0main.xyz/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/d0main.xyz/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
</VirtualHost>
</IfModule>
<IfModule mod_rewrite.c>
更新1:我通过删除
Redirect permanent / https://d0main.xyz
中的d0main.xyz-le-ssl.conf
解决了重定向错误,但是URL末尾缺少/
。例如,图形URL现在为https://d0main.xyzwp-content/image.jpg
更新2:这变得越来越奇怪。我在
Redirect permanent / https://d0main.xyz
中将行Redirect permanent / https://d0main.xyz\/
更改为d0main.xyz.conf
。现在,某些图像的两个斜杠(并且可以正常工作)为https://d0main.xyz//wp-content/uploads/2016/10/logo-5.png
,而其他图像的URL仍然没有斜杠:https://d0main.xyzwp-content/uploads/2016/10/image2.png
更新3:我忘记发布我的.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
更新4:我最后的(有效的)conf文件:
d0main.xyz.conf
<VirtualHost *:80>
ServerName d0main.xyz
ServerAlias www.d0main.xyz
ServerAdmin [email protected]
DocumentRoot /var/www/html
Redirect permanent / https://d0main.xyz/
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
# changed from None to FileInfo
AllowOverride FileInfo
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
d0main.xyz-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName delegatex.xyz
ServerAlias www.delegatex.xyz
ServerAdmin [email protected]
DocumentRoot /var/www/html
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
# changed from None to FileInfo
AllowOverride FileInfo
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
SSLCertificateFile /etc/letsencrypt/live/delegatex.xyz/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/delegatex.xyz/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
<IfModule mod_rewrite.c>
最佳答案
您不需要转义正斜杠,因此应该使用Redirect permanent / https://d0main.xyz\/
代替Redirect permanent / https://d0main.xyz/
。但是,在重定向(和ProxyPassing)时,应始终匹配尾部斜杠。
代替以下几行。
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
您应该为www.d0main.xyz和jsut做一个SSL虚拟主机
Redirect / https://d0main.xyz/
如果您仍然在使用双斜杠,那么原因似乎必须在其他地方。您有htaccess文件吗?
关于apache - 重定向错误:WordPress +让我们加密(Certbot)+仅SSL +非www,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39948113/