Why XAMPP Port 81 Redirects to Port 80 and Breaks Your Local Stack
When System.exe occupies port 80 on Windows, switching XAMPP Apache to port 81 is a valid workaround for getting the control panel and phpMyAdmin running. However, simply changing the listening port often introduces a subtle routing issue: requests to http://localhost:81/mywebsite get auto-redirected back to http://localhost/mywebsite, resulting in a "Site Not Found" error. This behavior is not caused by a typo in your wp-config.php or database tables; it is a fundamental mismatch between the server's virtual host configuration and the operating system's URL resolution logic.
The root of this problem lies in how Windows handles localhost. When you type http://localhost:81/... into a browser, the OS attempts to resolve localhost via DNS or the hosts file. If Apache is bound strictly to port 81 but your configuration still references the default domain context associated with port 80, or if the virtual host mapping isn't explicitly defined for the new port, the server may attempt a redirect based on its internal logic, often falling back to the default port behavior.
To resolve this without fighting System.exe, you must ensure that Apache's VirtualHost configuration explicitly binds the specific directory to the new port. The issue usually stems from the fact that XAMPP's default virtual host (httpd-vhosts.conf or similar) is configured for port 80. When you change the global server root in httpd.conf to listen on 81, the existing virtual host definitions might not be updated to reflect this change, causing the server to misinterpret the request path.
Here is the correct approach to fixing the redirect loop and enabling access to your local directories:
Verify Virtual Host Bindings
Open your primary Apache configuration file, typically located at C:\xampp\apache\conf\extra\httpd-vhosts.conf. Look for a <VirtualHost> block that defines your default site. You will likely see something resembling this:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
...
</VirtualHost>
Even if you changed the global port in httpd.conf, this block remains hardcoded to *:80. To force Apache to accept requests on port 81 without redirecting, update the virtual host binding:
<VirtualHost *:81>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
DirectoryIndex index.php index.html
<Directory "C:/xampp/htdocs/mywebsite">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
By explicitly binding the VirtualHost to *:81, you tell Apache that any request coming into port 81 belongs to this specific configuration, preventing it from attempting a redirect to port 80.
Check Hosts File Resolution
Another common pitfall occurs if your browser's DNS cache or the Windows hosts file is resolving localhost exclusively to port 80 behavior due to cached entries. Ensure that your C:\Windows\System32\drivers\etc\hosts file does not contain any entries mapping localhost to an IP address other than 127.0.0.1. If you have previously added custom mappings, clear them or ensure they do not interfere with the specific port logic.
Disable Auto-Redirect Logic in WordPress
If you are installing a new WordPress site on this stack, ensure that your .htaccess file does not contain rules that force redirects to the canonical domain (which might be hardcoded to localhost). In XAMPP environments, it is often safer to remove or comment out any redirect directives in the default .htaccess provided by WordPress until you are certain your virtual host configuration is stable.
# .htaccess - Keep this simple for local development
RewriteEngine On
# Remove any redirects like: RewriteRule ^(.*)$ http://localhost/$1 [R=301,L]
By aligning the VirtualHost binding, clearing cached DNS resolutions, and ensuring your application-level configuration doesn't fight the server's port settings, you eliminate the auto-redirect loop. This allows you to access http://localhost:81/mywebsite directly without relying on System.exe holding port 80.