Jump to content

Recommended Posts

Posted

Hi there,

Is there anyway in processwire to output the URL of the site, instead of the root. Because the root returns this value: "/" and I need it to return the URL.

Thanks in advance ;)

Posted

Hello there!

To get the full URL of page, try this: 

echo $page->httpUrl; // Current page URL
echo $pages->get(1)->httpUrl; // Home URL
  • Like 2
  • 3 years later...
Posted

Hi,

Sorry to dig up a so old topic, but I'm not satisfied with this answer.

$config->httpHost  return the url without the protocol (example.com)

And $pages->get(1)->httpUrl return the page with the language urlSegment (http://example.com/de)

Is there no way in Processwire to get a full site url, with protocol and domain name? The only solution I can see for me is to built it my self with $_SERVER values.

Thanks.

  • Like 1
Posted

Well, this is awesome. Particularly the $config->urls->httpFoo part.

A bit frustrated I couldn't find it myself through google. 

Thanks a lot!

  • 2 weeks later...
Posted

All the suggested options give me:

mysubdomainsite.maindomain.com

The site works fine on mysubdomainsite.com; getting that to show up in navigation is my problem.

Where is httpRoot defined? Can I edit it somewhere? Or is there a httpHome that is different from httpRoot?

Another dumb question from me...

 

 

  • 1 year later...
Posted

All those solutions give me back the first URL in the whitelist of hosts (config file).

I have two URLs in the whitelist (live domain and test domain) and I am looking for a way not always have to edit multiple URLs in the code when I switch between live and test environment.

Posted
On 12/7/2018 at 2:03 PM, David Bopp said:

All those solutions give me back the first URL in the whitelist of hosts (config file).

I have two URLs in the whitelist (live domain and test domain) and I am looking for a way not always have to edit multiple URLs in the code when I switch between live and test environment.

$config->httpHost should return current domain (if it's included in the httpHosts setting) or the first domain from said setting if no match was found. Here's the related code for reference: https://github.com/processwire/processwire/blob/341342dc5b1c58012ae7cb26cffe2c57cd915552/wire/core/ProcessWire.php#L308-L323.

If you're accessing your site with the dev domain and this domain is included in the httpHosts setting, that should be what this method returns. If not, I'd make sure that related settings are properly configured, and that your server works as expected (particularly in terms of SERVER_NAME and/or HTTP_HOST).

I'm not entirely sure what you're referring to with the "edit multiple URLs in the code" part, but generally speaking I'd recommend using relative paths etc. instead of fully qualified domains. This way it doesn't really matter which domain you access your site from. It's possible that you were actually referring to something else, so feel free to clarify this part ?

Edit: actually there's one more thing to keep in mind here, which is that ProcessWire prefers the ServerName value from the Apache VirtualHost block ($_SERVER['SERVER_NAME']) over the host header provided by the browser ($_SERVER['HTTP_HOST']) when determining httpHost. ServerName is used at least if Apache "UseCanonicalName" setting is "on", but this behaviour may apparently vary between different Apache versions.

In this case the solution would be either disabling the UseCanonicalName setting, or creating separate VirtualHost blocks for all domains you want to use with ProcessWire.

  • 3 years later...
Posted

When I use

echo $page->httpUrl;

I get the config url's, for example:
domain.com,www.domain.com, what is just included in the config

How do I get only one complete root URL incl. https://
maybe for <base href="<?php echo $urls->…; ?>" />

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...