[英]Redirecting www to non-www with http to https redirect and wildard subdomains
I just installed SSL certs but when visiting the www domain of my site it now shows the Apache2 Ubuntu default page.我刚刚安装了 SSL 证书,但是当访问我网站的 www 域时,它现在显示了 Apache2 Ubuntu 默认页面。 How do I redirect the www to non-www with http --> https and * subdomains?如何使用http --> https 和 * 子域将 www 重定向到非 www?
<VirtualHost *:80>
ServerName clearpath.site
ServerAlias *.clearpath.site
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =clearpath.site [OR]
RewriteCond %{SERVER_NAME} =*.clearpath.site
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
And me VH for port 443:而我的 443 端口的 VH:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName clearpath.site
ServerAlias *.clearpath.site
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/
SSLCertificateKeyFile /etc/letsencrypt/
</VirtualHost>
</IfModule>
Any help is appreciated.任何帮助表示赞赏。
Here's an example;这是一个例子; I've always been explicit in listing my subdomains, but you should be able to use wildcards: https://httpd.apache.org/docs/2.4/mod/core.html#serveralias我一直明确列出我的子域,但您应该能够使用通配符: https : //httpd.apache.org/docs/2.4/mod/core.html#serveralias
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com subdomain.example.com other.example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost *:443>
TimeOut 300
SSLEngine On
ServerName www.example.com
ServerAlias example.com subdomain.example.com other.example.com
# Set to the lobal Application Group
WSGIApplicationGroup %{GLOBAL}
# Pass Authorizations through to the WSGI app for Django REST Framework Token Auth
WSGIPassAuthorization On
WSGIDaemonProcess mysite-master-https python-home=/path/to/django/mysite-master/venv request-timeout=300 user=apache group=apache processes=6
WSGIProcessGroup mysite-master-https
WSGIScriptAlias / /path/to/django/mysite-master/config/wsgi.py process-group=mysite-master-https
<Directory /path/to/django/mysite-master/config>
Require all granted
</Directory>
Alias /static/ /path/to/django/mysite-master/static/
</VirtualHost>
Good luck!祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.