Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
patrickatwsrn opened this issue Jun 11, 2024 · 3 comments
Open

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

patrickatwsrn opened this issue Jun 11, 2024 · 3 comments
Labels
bug The issue in the code or project, which should be addressed.

Comments

@patrickatwsrn
Copy link

patrickatwsrn commented Jun 11, 2024

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 patrickatwsrn added the bug The issue in the code or project, which should be addressed. label Jun 11, 2024
@ant-tar
Copy link

ant-tar commented Jun 11, 2024

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

@jdaehne
Copy link
Contributor

jdaehne commented Jun 11, 2024

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.

@halftrainedharry
Copy link
Contributor

halftrainedharry commented Jun 11, 2024

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug The issue in the code or project, which should be addressed.
Projects
None yet
Development

No branches or pull requests

4 participants