localhost重定向后连接被拒绝求助:网站重设计本地环境故障
Hey there! Let's work through this connection refused problem you're facing with your local website rebuild. Here are actionable steps to narrow down and fix the issue:
Verify your local server is running properly
First, skip the redirect entirely and try accessing your site directly viahttp://localhost(add your custom port if you're using one, likehttp://localhost:8080). If this fails, your server (Apache/Nginx/XAMPP/etc.) might not be started. Check your server's control panel to confirm it’s running, or runcurl localhostin your terminal to test the connection.Audit your .htaccess redirect rules
Double-check that all remote URLs in your .htaccess have been replaced withlocalhost(including the correct port if needed). For example, a corrected rule might look like:Redirect 301 /old-path http://localhost/new-pathAlso, ensure your server allows .htaccess to take effect. For Apache, this means setting
AllowOverride Allin yourhttpd.confor virtual host config for your site's root directory—without this, your .htaccess rules won’t be applied at all.Search for hardcoded redirects in your site code
Redirects don’t always live in .htaccess. Scan your PHP, JavaScript, or template files for hardcoded URLs pointing to the remote site. For example, look for lines like:header("Location: https://your-old-remote-domain.com/some-page");Replace all instances of the remote domain with
http://localhost(plus port if required).Clear browser cache or use incognito mode
Browsers often cache 301 permanent redirects, which can cause old redirects to persist even after you’ve updated your config. Try accessing your site in an incognito window, or clear your browser’s cache (specifically cached redirects) to rule this out.Confirm your server’s port configuration
If your local server isn’t using the default port 80 (common with tools like XAMPP or WAMP), every redirect URL must include the correct port number. For example, if your server runs on port 8000, your redirects should point tohttp://localhost:8000/your-page—missing the port will lead to connection refusals since the browser tries to connect to port 80 where no server is listening.Check firewall/antivirus interference
Sometimes local firewalls or antivirus software block connections to your local server. Temporarily disable these tools and test your site—if the connection works, add your server’s port to the firewall’s allowed list to fix the issue long-term.
内容的提问来源于stack exchange,提问作者Leonel Matias Domingos

