Http to Https redirects suddenly not working in .htaccess? macOS Apache Might Be Running

All MAMP discussions around troubleshooting and anything related to MAMP. Be as detailed as possible here when posting an issue.
Post Reply
mampsupportmod
Site Admin
Posts: 161
Joined: Wed Jan 20, 2021 3:06 am

Http to Https redirects suddenly not working in .htaccess? macOS Apache Might Be Running

Post by mampsupportmod »

I use MAMP Pro for macOS. Recently, I noticed http to https redirects not working for majority of my sites (I have some sites behind Cloudflare that were working fine). My sites use an .htaccess for the http to https redirect. I had not modified the .htaccess files in years.


My .htaccess redirect config:

Code: Select all

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

First, I checked MAMP PRO -> Hosts -> SSL and ensured Allow to access this host via insecure http connections was enabled.

Mamp Pro Allow To Access This Host Via Insecure Http Connections
Mamp Pro Allow To Access This Host Via Insecure Http Connections (61.44 KiB) Viewed 12430 times

Then, I opened MAMP Pro -> Ports and User and discovered Apache non-SSL connections for MAMP Pro was running on port 81 instead of 80! I had MAMP Pro to always use port 80.


Mamp Pro Apache Port 81 Macos
Mamp Pro Apache Port 81 Macos (75.91 KiB) Viewed 12430 times


I coordinated the timing of the redirects not working after I performed a macOS system update. Sure enough, I discovered the macOS update re-enabled the default macOS Apache server on port 80 forcing MAMP Pro to use the next available port, 81.




The solution was simple - disable the default macOS Apache server so MAMP Pro Apache can run on port 80 again.


Make sure to stop MAMP Pro Apache before proceeding!


1. Open macOS Terminal and type:

Code: Select all

sudo apachectl stop

2. Ensure the default version of Apache is stopped by browsing to http://localhost:80/. The page should not load.


3. In order to disable the default macOS Apache server on future reboots, type the following command:

Code: Select all

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null

4. In MAMP Pro, go to Ports and User and change back the Apache non-SSL port to 80.


5. Start Apache for MAMP Pro.


Test your http to https redirects again - you should be set!



Takeaway: ensure the default macOS Apache server is not running after a macOS system update. You can check this by browsing to http://localhost:80/ when MAMP Pro Apache is not running.
MAMP Support Forums is an unofficial support forum covering MAMP & MAMP Pro solution stacks.
Post Reply