简体   繁体   English

http://example.com不会重定向到https://www.example.com

[英]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.comhttps://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.

相关问题 解析 http://www.example.com 以通过 htaccess 永久重定向到 https://example.com - Resolving http://www.example.com to permanently redirect to https://example.com via htaccess 如何将 http://www.example.com 重定向到 https://example.Z4D236D9A2D102C5ZFE6AD1Cware - How to redirect http://www.example.com to https://example.com with middleware htaccess重定向https:// www。 (https://www.example.com)到非www(https://example.com) - htaccess redirect https://www. (https://www.example.com) to non www (https://example.com) Apache2 使用虚拟主机将 https://example.com 重定向到 https://www.example.com - Apache2 redirect https://example.com to https://www.example.com with vhosts 如何将https://example.com/重定向到https://www.example.com/ - How to Redirect https://example.com/ to https://www.example.com/ 如何将 https://www.example.com/aaa 重定向到 https://example.com/aaa/ - how to redirect https://www.example.com/aaa to https://example.com/aaa/ 将* .example.com和example.com重定向到HTTPS的www.example.com时出现问题 - Problem with redirecting *.example.com & example.com to www.example.com for HTTPS 全部重定向到 https://www.example.com - Redirect all to https://www.example.com 强制从 https://example.com 重定向到 https://www.example.com - force redirection from https://example.com to https://www.example.com httpd.conf将https://example.com重写为https://www.example.com - httpd.conf rewrite https://example.com to https://www.example.com
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM