本地WordPress站点强制HTTPS无法访问求助(MAMP环境)
Hey there, let's work through this HTTPS issue you're hitting with your local MAMP setup. The error you're seeing happens because your site is configured to force HTTPS, but localhost doesn't have a valid, trusted SSL certificate out of the box—and depending on what you're doing, you might not even need one for local development. Here are two ways to fix this:
方法1:关闭站点的HTTPS强制跳转(最简单的方案)
Most local dev setups don't need HTTPS, so disabling the redirect is usually the quickest fix:
- First, check your site's root directory for a
.htaccessfile. Open it up and look for code that looks like this:
Either comment out these lines (add aRewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]#at the start of each) or delete them entirely, then save the file. - If you're using a CMS like WordPress, you'll also need to update your site URLs:
- Open your
wp-config.phpfile in the site root and add (or modify) these lines to use HTTP instead of HTTPS:define('WP_HOME','http://localhost/your-site-folder'); define('WP_SITEURL','http://localhost/your-site-folder'); - You should also update the URLs in your database: access phpMyAdmin through MAMP, find your site's database, open the
wp_optionstable, and change thesiteurlandhomefields to the same HTTP localhost URL.
- Open your
- For other CMS platforms (like Laravel, Drupal), check their configuration files: for example, in Laravel's
.envfile, setAPP_URL=http://localhost/your-siteinstead of the HTTPS version.
方法2:配置本地SSL证书(如果需要HTTPS测试)
If you specifically need to test HTTPS functionality locally, you can set up a trusted SSL certificate for MAMP:
- First, enable SSL in MAMP: Open MAMP Preferences, go to the
Apachetab, check theEnable SSLbox, and set the SSL port (default is 443, use 8443 if 443 is already in use). - MAMP comes with a default self-signed certificate, but browsers will still flag it as untrusted. For a smoother experience, use a tool like
mkcertto generate a locally trusted certificate:- Install
mkcert(it's a lightweight tool made for local dev), then runmkcert localhostin your terminal. This will generate two files:localhost.pem(certificate) andlocalhost-key.pem(private key). - Open MAMP's Apache configuration file (found at
MAMP/conf/apache/httpd.confor your site's virtual host config) and update the SSL lines to point to your new files:SSLCertificateFile "/path/to/your/localhost.pem" SSLCertificateKeyFile "/path/to/your/localhost-key.pem" - Add the generated certificate to your system's trusted root store (steps vary by OS: on macOS, double-click the
.pemfile and add it to the System keychain, then set its trust level to "Always Trust"; on Windows, use the Certificate Manager).
- Install
- Restart MAMP's Apache server, and your local HTTPS site should load without the invalid response error.
最后提醒
Whichever method you choose, make sure to restart MAMP's Apache server after making changes—otherwise the new settings won't take effect. If you still see issues, double-check for any other hardcoded HTTPS redirects in your site's codebase.
内容的提问来源于stack exchange,提问作者Josh

