gesp

Site url?

Recommended Posts

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 ;)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

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

Thanks a lot!

Share this post


Link to post
Share on other sites

With the latest dev version, you can also now do: $urls->httpRoot

  • Like 4

Share this post


Link to post
Share on other sites

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

 

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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.

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By zota
      Hi,
      After 2 or 3 cliks on my nav bar the browser starts to show
      http://julio.x10host.com/home/juliox15/public_html/logos/
      instead of
      http://julio.x10host.com/logos/
      Where or what should I start the fixing?
      Thanks
    • By louisstephens
      So I have a project where multiple pages are sending POST data to 1 single template page.  All was working well (well, at least with one ajax post), but now I have hit a stumbling block. I figured  the "best" way to handle the request were to use url segments and then use the following in the status page:
      if ($config->ajax && $input->urlSegment1 == 'add-bookmark') { // some code here } However, this doesnt seem to really work (as I assume the the request isnt being posted to /status/ but rather to /status/add-bookmark/). What is the best way to actually handle this?
    • By joelplambeck
      Hi Guys,
      I'm trying to do my first migration to the customers existing server (IIS 10) . I ran the site as a subdirectory on my website for test purposes (everything works fine).
      Following the tutorial of Joss, I tryed the site on a local xampp server to make sure, it also works on a root directory. So far so good, everything works.
      Now I moved the files (from the xampp) to the customers server. The root/index page is shown but for every subpage i get 404 Errors...
      Hence I followed the troubleshooting guide for not working URLs:
      On the first sight, the .htaccess file is not recognized, therefore I contacted the host support. They said, it is recognized but not all modules are supported in the processwire .htaccess file. I did the "öalskjfdoal" test in the .htaccess file and didn't get a 500 Error.... BUT the rewrite rule from the hosts support, to proof the file is read, DID work... The support claims, they do not provide debugging... so basically the .htaccess file is recognized and working, but not throwing any errors (for whatever reason).
      Working rewrite rule (from support):
      RewriteEngine On RewriteBase / RewriteRule ^test\.asp$ index.html [NC,L] RewriteRule ^test\.html$ konzept.html [NC,L] RewriteRule ^test2\.html$ team.html [NC,L] The support said, a couple modules are not supported in the htaccess file, the supported ones are listed here: http://www.helicontech.com/ape/ (I think mod_rewrite is supported)
      As I do not completely understand what exactly is happening in the htaccess file, I'm stuck. I tried all suggestions I found regarding this topic on the forum, but none of them solved the problem.
       
      .htaccess.txt
    • By louisstephens
      So I have a project coming up soon and one of the goals was to use Google's AMP project for the project's mobile site. I have gone through the tutorials and think I have a good grasp on the matter, but there is still one roadblock I do not really know how to tackle. The site, which uses a responsive grid system, will look great on a mobile and desktop which was is fine by me. However, if a user comes from Google to one of our AMP pages (ie www.example.com/amp) and clicks on a url, they will then be loading our responsive mobile pages and not the amp pages. For the sake of consistency, we really want to "force" users to stay on all the amp pages.
       
      My current thoughts on how to set up this task:
      Allow url segments for all pages using "/amp" Using a simple if statement, load the amp page if it exists <?php if($input->urlSegment1) { // add "&& $input->urlSegment1 == 'amp'" if you've more urlSegments include("partials/amp-page.php"); } else { include("partials/normal.php"); } ?>  
      However, I have hit a roadblock on appending "/amp" to all pages if they came to an amp page via Google, or even if they are on mobile and visit the site. Is this even possible to do, or should we just use the amp pages (if a user comes from google) and allow them to be active on our mobile pages?  We are just trying to give the fastest load times possible, as well as give a consistent look between mobile and desktop versions. As always, I really appreciate the ideas and help.
    • By modifiedcontent
      Another dumb question:
      Is there a field type for a text-based array?
      In my case I need to store an array of RSS feeds for SimplePie. Storing that list of links in a textarea - text formatted to look like an array - doesn't work with the script. It works with one link.
      The images field is an array. I assumed there would be an equivalent for URLs or text in general.
      Or is there another approach for these cases?
      Edit:
      I guess using the optional (module) Repeater field type is the best solution in this case? I have now a working solution based on that. Still curious about other ideas.