Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Root relative site URLs no longer work #3221

Closed
timkelty opened this issue Aug 21, 2018 · 4 comments
Closed

Root relative site URLs no longer work #3221

timkelty opened this issue Aug 21, 2018 · 4 comments

Comments

@timkelty
Copy link
Contributor

I think this was introduced here: c17487b#diff-8761a7cd35e729b6fadc9ebfa1200391

craft\helpers\UrlHelper::url will now always return a full url, even if your siteUrl is explicitly root relative (e.g. /)

@brandonkelly
Copy link
Member

brandonkelly commented Aug 26, 2018

I don’t think it was that commit, and don’t remember the exact issue off the top of my head, but the change was intentional.

@timkelty
Copy link
Contributor Author

Looking at the changelog, I'm guessing it was this:

Generated site URLs now always include full host info, even if the base site URL is root/protocol-relative.

So root/protocol relative values are ok in the siteUrl setting, but any generated URLs will have full path info. That seems a bit confusing to me.

My use-case for wanting a root-relative siteUrl is using Craft as a detached API, where having full URLs sometimes doesn't make sense. Obviously there are times where you do need a full URL though (URLs in email).

It almost seems like maybe there could be a third template rendering mode (CP, site, email/external) to manage things like this.

@brandonkelly
Copy link
Member

Right, that's the one. Committed in 4848022, which fixed #2919.

It’s pretty easy to turn an absolute URL into a root-relative URL using parse_url(), so maybe you could just use that when you need it?

$url = parse_url($url, PHP_URL_PATH);

@timkelty
Copy link
Contributor Author

so maybe you could just use that when you need it?

In my case that's not really a possibility (I don't think), as this is an API (CraftQL), not Twig – so I'd have to know any field/fieldtype that might use craft\helpers\UrlHelper::url and tap into it somehow.

If craft\helpers\UrlHelper::url had an event hook, that would be one way.

At this point, I'm all set: I'm just making the dev consuming my API parse the URI out. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants