Going to wp-admin without trailing slash incorrectly redirects when using localhost Router Mode

Issue Summary

In localhost Router Mode, going to http://localhost:10001/wp-admin redirects without the correct port to a 404 at http://localhost/wp-admin, but if I include a trailing slash (http://localhost:10001/wp-admin/), it correctly forwards to http://localhost:10001/wp-login.php and retains the port. Why does the port get dropped in the first case and how can I fix this?

Troubleshooting Questions

  • Does this happen for all sites in Local, or just one in particular?

All sites.

Replication

Create a brand new Wordpress site in Local WP using localhost Router Mode. Open the site (http://localhost:whateverport). Now try adding just “wp-admin” to the end of the URL (instead of “wp-admin/” with a trailing slash).

System Details

  • Which version of Local is being used?
    6.1.4+5521

  • What Operating System (OS) and OS version is being used?
    Windows 10 Pro and Windows 11 Pro

This sounds similar to these topic:

A few other questions:

  • What is the siteurl in the WordPress database?
  • What plugins or themes are installed?
  • Is there any change in functionality when disabling all plugins or themes?

Sorry, I mistakenly typed “Router Mode” when I meant “localhost Router Mode”. I edited my original question.

Both of those links you shared are basically the inverse of the problem I’m experiencing—they’re using Site Domains Router Mode instead of localhost Router Mode, and they are getting a port added to the URL when it shouldn’t be.

In my case, I’m using localhost Router Mode, and everything works great except the one wp-admin URL without a trailing slash, where the port gets removed from the URL when it shouldn’t be.

Visiting that last URL redirects me to http://localhost/wp-admin with no port (port 10001 disappears), which results in a 404 Not Found. I can’t reproduce this on any other server with the identical site code and database (except for a changed siteurl in the db, obviously).

I don’t have any plugins installed. This is a default Wordpress install, with the default template, with absolutely no content or plugins added. I’ve been happily using Local WP for over a year, but this problem occurs with every single site I’ve ever worked on with localhost Router Mode.

@ben.turner Any thoughts about this?

I was just able to replicate this. I’m not 100% sure where this is failing, but I think this might be a bug with our site’s nginx config not accounting for the port when redirecting.

I’ll keep investigating things and reply here when I have more info!

@ben.turner Cool, thanks for the reply! No rush, it’s just been one of those minor thorns in my side, mainly because I was worried that I might have something configured incorrectly with Local WP. I’m just happy to hear that you’re seeing the same problem and I’m not crazy. Thanks again.

I think I’ve zeroed in on what’s going on, and will create a bug for the Local devs to work on.

The actual fix will need a little more attention since we’ll have to consider all of the edge cases, but if you’re just using the localhost router mode, you should be able to update the nginx config for the site within the wordpress-single.conf.hbs file by adding :$server_port to the rewrite:

After making that change, stop the site and restart it in Local so that the configuration file is recompiled and loaded!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.