Apache将https非www重定向到https www(Ubuntu)
我知道像这样的问题已经贴了好几次了。但我面临着一个独特的问题,并寻求帮助。 我想将所有内容重定向到 我在Ubuntu 16上配置了LAMP并安装了Lets加密SSL。我还配置了重定向,状态如下:Apache将https非www重定向到https www(Ubuntu),apache,Apache,我知道像这样的问题已经贴了好几次了。但我面临着一个独特的问题,并寻求帮助。 我想将所有内容重定向到 我在Ubuntu 16上配置了LAMP并安装了Lets加密SSL。我还配置了重定向,状态如下: http非www和http www被正确重定向到https www https非www和https www都被反向重定向到https非www(而不是预期的https www) 以下是我的apache配置: 1。000默认le ssl.conf <IfModule mod_ssl.c> <
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName www.example.com
Include /etc/letsencrypt/options-ssl-apache.conf
ServerAlias example.com
SSLCertificateFile /etc/letsencrypt/live/getcreed.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/getcreed.com/privkey.pem
</VirtualHost>
</IfModule>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
</VirtualHost>
服务器管理员webmaster@localhost
DocumentRoot/var/www/html
ErrorLog${APACHE_LOG_DIR}/error.LOG
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
服务器名www.example.com
Include/etc/letsencrypt/options-ssl-apache.conf
ServerAlias example.com
SSLCertificateFile/etc/letsencrypt/live/getcreed.com/fullchain.pem
SSLCertificateKeyFile/etc/letsencrypt/live/getcreed.com/privkey.pem
2。000 default.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName www.example.com
Include /etc/letsencrypt/options-ssl-apache.conf
ServerAlias example.com
SSLCertificateFile /etc/letsencrypt/live/getcreed.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/getcreed.com/privkey.pem
</VirtualHost>
</IfModule>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
</VirtualHost>
服务器管理员webmaster@localhost
DocumentRoot/var/www/html
ErrorLog${APACHE_LOG_DIR}/error.LOG
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
重新启动发动机
重写cond%{HTTPS}关闭[或]
重写cond%{HTTP_HOST}^www\。[北卡罗来纳州]
重写cond%{HTTP_HOST}^(?:www\)?(.+)$[NC]
重写规则^https://www.%1%{REQUEST_URI}[L,NE,R=301]
请让我知道我做错了什么。任何帮助都将非常有用。这将使所有重定向到。例如,我正在使用我的网站
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?itechplanetpc\.com
RewriteRule ^(.*)$ https://www.itechplanetpc.com/$1 [R=301,L]
谢谢,伊凯莉·西里尔。我应该在哪里加上这个?将其添加到.htaccess或000-default-le-ssl.conf中没有帮助。000-default.conf已具有重定向规则。由于http得到了正确的重定向,我相信端口80正在按预期工作。但是https版本被重定向到非www,所以可能与端口443有关?将其添加到项目根目录中的.htaccess