【发布时间】:2017-02-18 06:36:24
【问题描述】:
注意:请参阅本文末尾的更新。对于最终(工作)配置文件,请参阅本文末尾的更新 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 contact@d0main.xyz
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 d0main@d0main.xyz
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:我通过删除 d0main.xyz-le-ssl.conf 中的 Redirect permanent / https://d0main.xyz 解决了重定向错误,但现在 URL 末尾缺少 /。例如,图形 URL 现在是 https://d0main.xyzwp-content/image.jpg
更新 2:这越来越奇怪了。我将d0main.xyz.conf 中的Redirect permanent / https://d0main.xyz 行更改为Redirect permanent / https://d0main.xyz\/。现在有些图片有两个斜线(并且有效)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:我的最终(工作)配置文件:
d0main.xyz.conf
<VirtualHost *:80>
ServerName d0main.xyz
ServerAlias www.d0main.xyz
ServerAdmin contact@d0main.xyz
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 delegatexyz@gmail.com
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>
【问题讨论】:
标签: apache ssl mod-rewrite https url-rewriting