Configure Local so two URLs go to same site (and keep url)

What issue or error are you experiencing?

I have two urls (dev.local.sitename.com and dev.local.sitename2.com) configured in my WIndows hosts file as going to 127.0.0.1 and ::1. dev.local.sitename.com is the main url. When I attempt to go to dev.local.sitename2.com, I get redirected to dev.local.sitename.com before wp-config.php is run.

How do I get this redirect to either stop, or wait until after wp-config.php?

I guess the real question is: where are the config files for the web server that Local is using on my machine?


What steps can be taken to replicate the issue? Feel free to include screenshots, videos, etc

Create a site. Point two different urls to the site. Only the main site responds and any others redirect to the main site.


System Details

  • Local Version:
    Latest

  • Operating System (OS) and OS version:
    Windows


Local Logs

Attach your Local Logs here (Help Doc - Retrieving Local’s Log)

local-lightning.log (718.3 KB)


Security Reminder
Local does a pretty good job of scrubbing private info from the logs and the errors it produces, however there’s always the possibility that something private can come through. Because these are public forums, always review the screenshots you are sharing to make sure there isn’t private info like passwords being displayed.

Hi @Owen37

I’m not sure I understand so apologies here but for clarity are you trying to create a multisite install?

Create a site. Point two different urls to the site. Only the main site responds and any others redirect to the main site.

Why would you need two URLs pointing to the same install?

Actually, no, I’m not trying to create a multisite (that will not do what we need since a multisite uses different tables per site). We need two different URLs to go to the same site and tables and then use php, javascript, and stylesheets to change a few things about the site for branding. Almost all the data will be the same between sites.

If you look at www1.auntminnie.com and www.auntminnieeurope.com, that is exactly what is happening (except they are asp.net websites running on IIS and MSSQL: same code, different configs).

At any rate, we now have our new WordPress site at my.auntminnie.com and we need to get my.auntminnieeurope.com to share the SAME database (users and other data) and just show a slightly different look (stylesheets, etc) based on the URL.

TIA,

Owen Mortensen

Senior Software Engineer

Science And Medicine Group

Hey @Owen37 , Local can’t do what you’re describing out of the box. I think the only way you can get something like this to sort of work is roughly like this:

  1. Create a new, plain, Sub-domain multisite (this will create the necessary settings in Local to allow multiple subdomains to reach a specific Local site)
  2. Edit the wp-config.php file for that site and comment out the multisite settings
  3. Manually add the subdomains you want to your hosts file. Note that you’ll need the domains to be subdomains and not two different top-level domains. So dev1.example.local and dev2.example.local would work, but example.local and myexample.local wouldn’t.
  4. Do your site-specific code within the WP site

I haven’t done this, so I don’t know how fragile this is or if the changes get wiped out during updates.

If that doesn’t work, then your other option would probably be to use Local in “localhost” router mode, and then manually spin up your own proxy server to resolve the domains to the individual sites.

But why can’t I just edit…

I don’t think you will be able to edit Local’s default server to get what you need.

There are at least two “web servers” in play (see this help doc: What is Router Mode? for more details), to summarize:

  • Each WP site has one web server (nginx/apache), which listens on an open port (like localhost:10010)
  • The Local router proxies the site’s domain to the individual site’s web server

For what you’re describing, you would need to edit the Local Router’s configuration. That config is found within the user configuration folder, within the run/router sub-folder. Here’s where that is on my Mac. For you on windows, it will be similar, but located in your User folder, under AppData > Roaming > Local

The problem is that there isn’t a way for you to update that file and have it re-loaded into the running Nginx process. Every time Local starts a site, it compiles these configuration files and reloads the nginx process using the values that are set in the Local UI. There isn’t a way to set multiple domains for a regular site within the Local UI.

The reason that creating a multisite within Local might work, is that the nginx config that it uses listens for a wildcard subdomain.

I know this is a rambling reply, but hopefully it gets you something you can use. Let us know if you have any other questions!

1 Like

Thank you for the detailed reply. Due to the complexity (and probably unstable) of the solutions, we’re probably going to find another way to specify which “branding” should appear on the site as a user navigates through it with just the one domain.

Regards,

Owen Mortensen

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