[英]http://example.com would not redirect to https://www.example.com
we have this two conf on our webserver. 我们的网络服务器上有两个conf。
http: http:
<VirtualHost *:80>
ServerName www.example.de
ServerAlias example.de www.example.at example.at www.example.net example.net
RewriteEngine On
RewriteCond %{HTTP_HOST} off
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}
# Error page is just the index telling about the situation of not being connected
ErrorDocument 404 /index.html
</VirtualHost>
https: https:
<IfModule mod_ssl.c>
NameVirtualHost *:443
<VirtualHost *:443>
ServerName www.example.de
ServerAlias example.de www.example.at example.at www.example.net example.net
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/www.example.de/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.de/privkey.pem
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ %{REQUEST_SCHEME}://www.%{HTTP_HOST}$1 [R=301,L]
DocumentRoot /var/www/homepage/web
<Directory /var/www/homepage/web>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/example-ssl.error.log
CustomLog ${APACHE_LOG_DIR}/example-ssl.access.log combined
</VirtualHost>
</IfModule>
When I try to open http://www.example.com then it would be redirect to https://www.example.com 当我尝试打开http://www.example.com时 ,它将重定向到https://www.example.com
When I try to open http://example.com or https://example.com , then I got the error "Page not available" 当我尝试打开http://example.com或https://example.com时 ,出现错误“页面不可用”
What is wrong in my both conf-Files on the Webserver? 我在Web服务器上的两个conf文件有什么问题? Both should redirected to the https://www.example.com url.
两者都应重定向到https://www.example.com网址。
Please, try to avoid mod_rewrite unless there is no other option. 请尽量避免使用mod_rewrite,除非没有其他选择。 As you can see it's complicated and will make your life harder for the simpler tasks.
如您所见,它很复杂,会使您的生活变得更简单。
A single Redirect will do to redirect everything to the SSL virtualhost: 单个重定向将把所有内容重定向到SSL虚拟主机:
Redirect / https://www.example.de/
Note: Redirect depends on mod_alias, so no need to RewriteEngine on or such either in the non-SSL virtualhost. 注意:重定向取决于mod_alias,因此无需在非SSL虚拟主机中使用RewriteEngine即可。
If you insist on using mod_rewrite because you have many names and need the variables: 如果您坚持使用mod_rewrite是因为您有很多名称并且需要变量:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*) https://www.%{HTTP_HOST}/$1 [R,L]
RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [R,L]
The first one catches those cases where host does not start with www, the second catches the rest. 第一个捕获主机不是以www开头的情况,第二个捕获其余情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.