0

I'm using XAMPP to run a apache/php/mysql/wordpress server. I'm trying to understand the rewrite module and it's not making much sense to me because of how I have it configured and the results I'm getting are not expected.

Expected Results:

The following URLs will all get redirected to https://www.example.com.

What I'm Seeing Happen:

The first two work great, it's the third one that does not seem to be working correctly. I'm not really sure how the first one is even working though. I have a vhost configured for ServerName www.example.com:80 and nothing for ServerName example.com:80.

Does anyone have any idea what I have configured incorrectly? Thanks!


Contents of \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 admin@example.com
    
    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>

Contents of \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 admin@example.com
    
    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 admin@example.com
    
    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>
Arvo Bowen
  • 805
  • 5
  • 17
  • 35

0 Answers0