Being redirected to 127.0.0.1 from IPv4 Address

Being redirected to 127.0.0.1 from IPv4 Address

September 5, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Being redirected to 127.0.0.1 from IPv4 Address

Debugging Local Website Access Across Networks

The Challenge

You’re in the middle of developing a Magento e-commerce site on your local WampServer setup and you want to test its responsiveness directly from your phone. However, when trying to access the project via your device’s IP address (e.g., 10.1.100.126/magento), you’re being redirected to 127.0.0.1/magento—which fails because your server isn’t on the phone.

Understanding the Redirection

This redirection issue occurs due to how Apache handles requests in a local development environment. By default, the .htaccess file used by Magento contains rules that force all requests to redirect to localhost.

Here’s what happens when you access 10.1.100.126/magento:

  1. Your phone sends an HTTP request to your computer at IP address 10.1.100.126.
  2. The request hits Apache, which checks the .htaccess file for any rules.
  3. The Magento-specific redirection rule in the .htaccess file kicks in and rewrites the URL from 10.1.100.126/magento to 127.0.0.1/magento.
  4. Your phone’s browser receives a 301 or 302 redirect response, but since 127.0.0.1 is your local loopback address (not reachable from the network), the page fails to load.

Identifying Relevant Configuration Files

The key file causing this issue is usually found at:

/path/to/your/project/.htaccess

In a Magento setup, this file typically contains lines like these:

RewriteEngine On
RewriteRule ^api/soap/?$ index.php [L]
RewriteRule ^api/rest/?$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.*)?index.php($|/)
RewriteRule .* index.php [L]

Solving the Redirection Issue

To resolve this, you have two main options:

1. Modify the .htaccess File Locally

You can edit the local .htaccess file to remove or comment out the problematic redirection rules. This changes your development setup but maintains the redirection for production purposes.

# sudo nano /path/to/your/project/.htaccess

Comment out (or delete) the lines causing the redirection:

# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond %{REQUEST_URI} !(.*)?index.php($|/)
# RewriteRule .* index.php [L]

2. Update Your Network Settings Temporarily

For a quick test, you can update your phone’s hosts file to map 127.0.0.1 to your computer’s local IP address.

For Android:

  1. Enable Developer Options (Settings > About Phone > Tap “Build number” 7 times).
  2. Go back and select “Developer Options”.
  3. Activate USB debugging.
  4. Connect your phone and allow it in the “Allow USB debugging” dialog.
  5. Run a command like this on your computer:
adb shell 'echo -e "\n10.1.100.126\t127.0.0.1\n" >> /system/etc/hosts'

This temporarily maps 127.0.0.1 to your local IP address on the phone, allowing you to view the site.

Conclusion

Redirection issues like this are common in local development environments due to default Apache configurations designed for production use cases. By understanding and modifying the relevant .htaccess file or temporarily updating network settings, you can successfully access your locally hosted Magento project from your mobile device for responsive design testing.

Remember that these changes affect only your local setup; the redirection will still apply in a live environment after deployment.

For more on local development best practices and debugging techniques, check out our guide: Streamlining Your Local Development Workflow.

API Configuration Errors

Our network