apache - HTTP + HTTPS + www + 非 www Apache 配置
问题描述
在我的 Apache 配置中,所有内容都被重定向到 HTTPS(这很好)。但两者https://www.example.com
并https://example.com
仍然存在。
问题:如何只有https://www.example.com
而不是非www?
我应该使用一种301 Redirection
技术还是另一种技术?
应该如何更改这样的配置:
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
ServerAlias *.example.com
DocumentRoot /home/www/example
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
</VirtualHost>
</IfModule>
?
解决方案
Relymcd 的回答解决了这个问题,但它还需要存在证书行(如果没有,它将失败):
<VirtualHost *:443>
ServerName example.com
Redirect 301 / https://www.example.com/
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
</VirtualHost>
推荐阅读
- android - 为什么我的网站在 OnePlus 5T 上呈现如此糟糕?
- c# - 无法从 XPath 获取数据
- python-3.x - Selenium(python 库)无法使用 send_keys 函数上传
- python - 指数移动平均差异?
- javascript - 如何在单击时隐藏带有按钮类名的 div?
- php - 从 instagram __a=1 用 php 读取 JSON
- android - 即使视图位于其顶部,BottomNavigationView 也是可见的
- c++ - 为什么当我在超类中打印并在派生类中扩展此函数时,它在 C++ 中不显示特定属性?
- ios - 导航堆栈上更新的视图控制器更改时未触发通知
- java - 如何为从数据库中获取数据的获取请求编写通用方法?