Dashboard etc. not obeying WP_HOME/WP_SITEURL??
-
Quick summary of situation:
This is a private blog area which is manually proxied by a route in a custom web app, because the custom app has custom authentication and the client wanted the blog to be behind the same authentication. It’s docker-compose, with an nginx container in front and an ASP.NET Core MVC container behind that (which lives at/app/
), and there’s a particular controller route in that MVC app (/app/privateblog/
) that just relays requests to the internal docker-compose address for the private blog container.
(Diagram in case that was hard to follow: )
This was originally a Ghost blog container, and it worked as designed. But Ghost wasn’t meeting the client’s needs as a blog engine, so we decided to simply switch the Ghost container out for a WordPress container.
Which I thought would be pretty much drop-in.
But it’s not.The problem is that WordPress doesn’t fully respect a setting telling it what its URL is.
With Ghost, this was as simple as a single environment line in my docker-compose.yml and everything just worked:
composename.blog.privateghost: image: ghost environment: url: "https://example.com/app/privateblog"
So naturally, when I went to switch it over to WordPress, I googled around and I came up with this:
composename.blog.privatewordpress: image: wordpress environment: WORDPRESS_CONFIG_EXTRA: | define('WP_HOME','https://example.com/app/privateblog'); define('WP_SITEURL','https://example.com/app/privateblog');
Now, that works well enough to complete the initial installation, but WordPress frequently ignored it and would redirect to
https://composename.blog.privatewordpress
.
For example, If you visit/app/privateblog/wp-admin
, WordPress feels the need to redirect you just to slap on a trailing/
, but in doing so it redirects you tohttps://composename.blog.privatewordpress/wp-admin/
instead of/wp-admin/
being on the end of the externally facing path defined inWP_HOME
andWP_SITEURL
.
(I’m not sure where it’s even getting thecomposename.blog.privatewordpress
URL in order to use it instead, as docker-compose isn’t providing any internal dns or anything, so it must be getting it out of the incoming request headers from the internally forwarded request or something? Why would it DO that if WP_HOME and WP_SITEURL are things?)
After googling around some more, I found a suggestion to add this line to the wp-config block in my WORDPRESS_CONFIG_EXTRA:
$${_SERVER}['HTTP_HOST'] = $${_SERVER}['HTTP_X_FORWARDED_HOST'];
That didn’t seem to improve the situation (although, as I type that, I realize I should probably double-check that the manual proxy controller code is even attaching any X-Forwarded headers; I’ll get back to this on that)…
I also saw some stuff about doing astr_replace
of_SERVER['REQUEST_URI']
in there, but that seemed to be about correcting paths below the domain name and doesn’t fit very well intocomposename.blog.privatewordpress
–>example.com/app/privateblog
…Now way over budget for this simple change, in order to try to put it to bed I went the route of brutely rewriting the Location header in the responses coming back from the proxy to string replace any instance of the URL configured to redirect to (
https://composename.blog.privatewordpress
) with the path of the proxying controller (https://example.con/app/privateblog
).
I then did the same thing with url-encoded versions, in case it was escaped in a querystring as aredirect_to
or anything like that.Problem solved?
Still no.
Because sometimes it’s not in a redirect header, it’s a link in text on the rendered pages.
Best example, because it’s 100% consistent:
The 2nd page of the list of Pages in the dashboard.
Why does that ignore
WP_HOME
andWP_SITEURL
?? Where does it get its information from instead? Doesn’t this cause problems for all sorts of people who needWP_HOME
orWP_SITEURL
to work properly?? Is there some setting I can change to make it stop behaving this way???
I don’t really want to brutely string-replace the response content, that seems way too far down the wrong track ??
- The topic ‘Dashboard etc. not obeying WP_HOME/WP_SITEURL??’ is closed to new replies.