Jump to content

Site url?


adinuno
 Share

Recommended Posts

  • 3 years later...

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
Link to comment
Share on other sites

  • 2 weeks later...

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...

 

 

Link to comment
Share on other sites

  • 1 year later...

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 years later...

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->…; ?>" />

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...