Using Domain name instead of localhost in with https in xampp

Using Domain name instead of localhost in with https in xampp

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Resolving HTTPS Redirection Loops and Virtual Host Issues in XAMPP

When configuring a local development environment like XAMPP on Windows, the transition from HTTP to HTTPS often reveals subtle misconfigurations that break virtual host resolution. A common scenario involves setting up a custom domain, such as www.mysite.com, via your hosts file and Apache virtual hosts configuration. While this setup functions perfectly over HTTP, enabling SSL frequently results in unexpected behavior: accessing https://mysite.com might redirect to a path like /xampp/ instead of serving the intended content, or fail entirely.

The root cause of these issues usually lies in how Apache interprets the ServerName, the binding of the SSL port, and the interaction between the HTTP and HTTPS virtual hosts. In your specific case, where http://mysite.com works but https://mysite.com redirects to the XAMPP welcome page, the server is likely receiving the request on port 443 but failing to match it to the correct virtual host definition because of a mismatch in the NameVirtualHost directive or the ServerName configuration.

Understanding Virtual Host Bindings

In your current httpd-vhosts.conf, you have defined a virtual host for www.mysite.com bound to 127.0.0.1. This works for HTTP because the standard Apache port (80) is listening on the loopback interface. However, when enabling SSL, Apache expects the server block to listen specifically on the IP address and port combination where the certificate is active.

If you replace 127.0.0.1 with *:443 in the virtual host definition, you are instructing Apache to bind that specific domain configuration to all interfaces on port 443. This is a common pitfall. When you do this without adjusting the global Listen directive or ensuring the certificate paths are correct, Apache may reject the start command because it conflicts with the default SSL virtual host (often listening on *:443 for the localhost domain).

The redirect to /xampp/ suggests that the request is being handled by a generic default virtual host rather than your custom one. This often happens if the ServerName does not match exactly what is requested, or if the port binding prevents Apache from distinguishing between the HTTP and HTTPS instances of your custom domain.

Correcting the Configuration

To resolve the HTTPS redirection issue while keeping localhost accessible, you should ensure that your virtual hosts are bound to the loopback interface explicitly when using SSL in a local-only environment. Instead of using *:443, keep the binding specific to 127.0.0.1.

Here is how the corrected configuration should look:

NameVirtualHost 127.0.0.1:80
NameVirtualHost 127.0.0.1:443

<VirtualHost 127.0.0.1:80>
    ServerName localhost
    DocumentRoot "C:/xampp/htdocs"
</VirtualHost>

<VirtualHost 127.0.0.1:80>
    ServerName www.mysite.com
    ServerAlias mysite.com
    DocumentRoot "C:/xampp/htdocs/mysite"
</VirtualHost>

<VirtualHost 127.0.0.1:443>
    SSLEngine on
    SSLCertificateFile "C:/xampp/apache/conf/ssl/server.crt"
    SSLCertificateKeyFile "C:/xampp/apache/conf/ssl/server.key"
    
    ServerName www.mysite.com
    ServerAlias mysite.com
    DocumentRoot "C:/xampp/htdocs/mysite"
</VirtualHost>

<VirtualHost 127.0.0.1:443>
    SSLEngine on
    SSLCertificateFile "C:/xampp/apache/conf/ssl/cert.crt"
    SSLCertificateKeyFile "C:/xampp/apache/conf/ssl/key.key"
    ServerName localhost
    
    DocumentRoot "C:/xampp/htdocs"
</VirtualHost>

Key adjustments include adding NameVirtualHost directives for port 443 and creating a dedicated virtual host block for the localhost domain over HTTPS. This ensures that when you request https://localhost, Apache serves the root directory, and when you request https://mysite.com, it serves the specific document root defined in that block.

Managing SSL Certificates and Redirection Logic

The redirect to /xampp/ often stems from a misconfigured .htaccess file or default XAMPP behavior when SSL is enabled without a proper virtual host match. If you have RewriteEngine On in your .htaccess files, ensure that the RewriteBase and RewriteRule directives are not inadvertently forcing a redirect based on an incorrect canonical URL.

When using self-signed certificates generated via OpenSSL (commonly included with XAMPP), ensure that the certificate chain includes the correct Common Name (CN) or Subject Alternative Name (SAN). If the browser does not trust the certificate, it may display a warning, but it should still resolve the domain correctly if the virtual host binding is accurate.

Avoid forcing Listen 80 and Listen 443 globally if you intend to bind specific IPs in your virtual hosts, although XAMPP often handles this automatically via the main config file. The critical step is ensuring that the ServerName inside the SSL virtual host block matches the URL you are trying to access exactly.

For production-like environments or more complex setups involving multiple domains, consider using httpd-vhosts.conf with distinct blocks for each domain and port combination. If you encounter persistent issues, check the Apache error log located at C:/xampp/apache/logs/error.log. This log will explicitly state why a virtual host failed to start or why a request was routed to the default location.

By strictly binding your SSL virtual hosts to 127.0.0.1 and separating the configuration for localhost and your custom domain, you eliminate cross-contamination between HTTP and HTTPS traffic. This approach provides a stable foundation for local development with secure connections without relying on generic redirects or ambiguous port bindings.

Our network