XAMPP 重定向问题,如何让 https://example.com 重定向到 https://www.example.com?

XAMPP 重定向问题,如何让 https://example.com 重定向到 https://www.example.com?

我正在使用 XAMPP 运行 apache/php/mysql/wordpress 服务器。我试图理解重写模块,但由于我的配置方式以及我得到的结果不是预期的,因此对我来说没有多大意义。

预期成绩:

以下 URL 都将重定向到https://www.example.com

我所看到的情况:

前两个运行良好,第三个似乎运行不正常。但我不太确定第一个是如何工作的。我为 配置了一个 vhost,ServerName www.example.com:80但没有为 配置任何内容ServerName example.com:80

有人知道我配置错误了吗?谢谢!


内容\xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "C:\sites\localhost"
    ServerName localhost
    ServerAdmin admin@localhost
    
    ErrorLog "C:/xampp/apache/logs/localhost/error.log"
    TransferLog "C:/xampp/apache/logs/localhost/access.log"
    
    <Directory "C:\sites\localhost">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost 192.168.1.10:80>
    RewriteEngine on
    
    ServerName www.example.com:80
    ServerAdmin [email protected]
    
    ErrorLog "C:/xampp/apache/logs/example_com/error.log"
    TransferLog "C:/xampp/apache/logs/example_com/access.log"
    
    RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
</VirtualHost>

内容\xampp\apache\conf\extra\httpd-ssl.conf

<VirtualHost 192.168.1.10:443>
    SSLEngine on
    SSLCertificateFile "C:\certs\example.com\example_com.crt"
    SSLCertificateKeyFile "C:\certs\example.com\example_com_decrypted.key"

    DocumentRoot "C:\sites\example.com"
    ServerName www.example.com:443
    ServerAdmin [email protected]
    
    ErrorLog "C:/xampp/apache/logs/example_com/error.log"
    TransferLog "C:/xampp/apache/logs/example_com/access.log"
    CustomLog "C:/xampp/apache/logs/example_com/ssl_request.log" \
      "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    
    <Directory "C:\sites\example.com">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
    
    <FilesMatch "\.(cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory "C:/xampp/apache/cgi-bin">
        SSLOptions +StdEnvVars
    </Directory>

    BrowserMatch "MSIE [2-5]" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0

</VirtualHost>

<VirtualHost 192.168.1.10:443>
    RewriteEngine on
    SSLEngine on
    SSLCertificateFile "C:\certs\example.como\example_com.crt"
    SSLCertificateKeyFile "C:\certs\example.com\example_com_decrypted.key"
    
    ServerName example.com:443
    ServerAdmin [email protected]
    
    ErrorLog "C:/xampp/apache/logs/example_com/error.log"
    TransferLog "C:/xampp/apache/logs/example_com/access.log"
    CustomLog "C:/xampp/apache/logs/example_com/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
          
    RewriteRule ^(.*) https://www.%{SERVER_NAME}$1 [R,L]
</VirtualHost>

相关内容