revolution icon indicating copy to clipboard operation
revolution copied to clipboard

[2.x] site_url returns IP address instead of domain url

Open patrickatwsrn opened this issue 1 year ago • 3 comments

Bug report

Summary

Quick summary what's this issue about.

Today some image links returned a path that included the ipv6 address instead of the domain name.

<base href="[[!++site_url]]">

returns

base href="xxxx:xxxx:xxx:xxxx::1" 

instead of

base href="https://example.com/" 

This happens occationally (2-3 times per year) on other pages and I always "fix" it by hard-wiring the domain name into my tag.

I can also remember this problem to be popping up on acnchor links inside chunks using the scheme modifier.

[[~1? &scheme=full]]

Step to reproduce

It just happens, clearing the site cache solves the problem.

This seems to be a very old problem that occationally pops up:

(2011) https://forums.modx.com/thread/13720/site-url-returns-ip-address (2022) https://community.modx.com/t/links-randomly-changing-to-ip-address/5493

Observed behavior

n.a.

Expected behavior

In a single context environment, site_url should always return the domain name. In a multi-contecxt environment site_url should return the site_url of the current context.

Environment

MODX 2.8.6, PLESK Server running Ubuntu

patrickatwsrn avatar Jun 11 '24 08:06 patrickatwsrn

I saw the same behavior once for 2.8.x, hard-coding solved the issue

ant-tar avatar Jun 11 '24 08:06 ant-tar

I have the same behavior on a specific site on a specific hosting server. After clearing the MODX cache everything ist good again for a few month. Then suddenly it appears again.

Because this happens only on this server - I think it has to to with the hosting environment.

jdaehne avatar Jun 11 '24 10:06 jdaehne

Like explained in the first link you posted, by default site_url is set for every request based on the request itself (in the file core/config/config.inc.php by using $_SERVER['HTTP_HOST'], $_SERVER['HTTPS'], etc.).

For example:

  • When you request http://127.0.0.1/mypage.html , [[!++site_url]] is http://127.0.0.1/
  • When you request http://localhost/mypage.html , [[!++site_url]] is http://localhost/

If site_url is always used uncached (e.g. [[!++site_url]]), this shouldn't create any issues. If site_url is used cached (e.g. [[++site_url]]), this can create issues, because the first request (after the cache is cleared) defines the value of site_url (in the cached file) for all future requests (until the cache is cleared again).


To avoid the problem, use site_url always uncached. Or you can create site_url/http_host context-settings/system-settings (to overwrite the generated values (from the request) in config.inc.php). Or maybe you can change the .htaccess file to make sure that your site is always accessed with the same %{HTTP_HOST} value.

halftrainedharry avatar Jun 11 '24 15:06 halftrainedharry

@patrickatwsrn that sounds like it may be an environment issue since you're calling it uncached. Are you still running into this and have you figured out a way to repeat it? Which version of PHP?

rthrash avatar Mar 13 '25 21:03 rthrash