Jump to content
Guy Incognito

Another thread about paths when Bootstrapping PW

Recommended Posts

Have read loads of similar threads but can't find the deifnitive answer. I'm bootstrapping ProcessWire into a Magento installation. Everything is working fine in terms of expected PW API functionality, however I cannot get the paths for images in the site work correctly.

ProcessWire is installed in a subfolder called 'pw'.

If I load the PW site directly e.g. visit mainsite.com/pw everything loads fine and all image paths are correct. If I load the parent site in the root folder with the PW bootstrapped page content rendered within it, the image paths don't contain the subfolder and so are broken. So I get

https://mainsiteexample.com/site/templates/img/test.jpg

instead of

https://mainsiteexample.com/pw/site/templates/img/test.jpg

I've tried updating the rewrite base in the .htaccess file but it doesn't seem to make any difference. Have also tried various settings in the config file to no avail. Wondering if rewrite base perhaps isn't working as intended because I'm behind a NGINX/Apache hybrid environment?

Share this post


Link to post
Share on other sites

Thanks @wbmnfktr - I did take a look at this and couldn't get anything working. I'm not sure at this stage if this is a server config issue my end or I'm not using ProcessWire as intended in this scenario. It seems to me that PW is grabbing site root from the parent page where the embedded bootstrap content is rather than the PW installation itself. Is this expected behaviour?

Share this post


Link to post
Share on other sites

I honestly don't know. Never bootstraped ProcessWire into something in the last two years or installed it into a subfolder. Sorry.

  • Thanks 1

Share this post


Link to post
Share on other sites

Ah ha moment - I think I got it!

Setting the root url in the template seems to have solved the issue. Although I think as per your post @wbmnfktr there's possibly a less destructive/repetitive way to this in future if can get my head round it!

<?php $config->urls->root = '/pw/';?>

 

  • Like 3

Share this post


Link to post
Share on other sites
42 minutes ago, dragan said:

Can't you just use httpUrl instead of url?

That was my first thought too but it seemed to produce different output when bootstrapped vs loading as ‘native’ ProcessWire.

Although I’ve now solved it, my hunch is still the rewritebase option in htaccess wasn’t working as intended. It could be because of the NGINX Apache proxy setup.

For the record since I left the office for the day it dawned on me that the link @wbmnfktr posted above to Ryan’s updates on the customisable paths probably will work - but I think it may currently require the dev branch whereas this site is running master. 

Share this post


Link to post
Share on other sites
17 hours ago, matjazp said:

Interesting - I did try to call setLocation() from ready and init and both threw an error even though the blog post indicates they’re callable from there.

Edited by Guy Incognito
Typo that didn't make any sense!

Share this post


Link to post
Share on other sites
13 hours ago, Guy Incognito said:

For the record since I left the office for the day it dawned on me that the link @wbmnfktr posted above to Ryan’s updates on the customisable paths probably will work - but I think it may currently require the dev branch whereas this site is running master.

 

13 hours ago, Guy Incognito said:

Interesting - I did try to call setLocation() from ready and init and both three an error even though the blog post indicates they’re callable from there.

 

Which pw version are you running?

Share this post


Link to post
Share on other sites
10 minutes ago, Guy Incognito said:

This site is 3.0.123.

Yep, I think the most tips above linking to the blog are only valid for greater pw versions. (Dev-Branch)

  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ajt
      Hello!
      I want to keep sort some pages in my page tree within a single parent, but then have the URLs for those pages ignore their topmost parent.
      So for example, if the page is at: [home]/buildings/architect-name/building-name
      I want the URL to be /architect-name/building-name
      I've search around the forum, and the solution that comes up everywhere is a version of the code from this post: 
      /** * This hook modifies the default behavior of the Page::path function (and thereby Page::url) * * The primary purpose is to redefine blog posts to be accessed at a URL off the root level * rather than under /posts/ (where they actually live). * */ wire()->addHookBefore('Page::path', function($event) { $page = $event->object; if($page->template == 'post') { // ensure that pages with template 'post' live off the root rather than '/posts/' $event->replace = true; $event->return = "/$page->name/"; } }); And I can use a version of that to successfully get buildings/architect-name to appear as /architect-name
      But /buildings/architect-name/building-name still appears as /buildings/architect-name/building-name
      Is there a way to get URLs to ignore/remove that topmost parent even when the page has a grandchild?
      Any help much appreciated!
    • By louisstephens
      So I have been diving into vue.js lately, and I am really impressed. I thought it could be perfect for an internal dashboard using PageQuerry boss to retrieve the data. However, I do have a few questions that someone might be able to guide me with before I fully commit. 
      1. Is it even possible to bootstrap pw into a vue app?
      2. How would it be possible to handle user registration/logins without actually having to mirror the users on pw in another service? 
      3. I know I could easily use an iframe in a modal to handle page editing (as I have done it inside of pw before), but would this be the best solution?
    • By Guy Incognito
      I'm trying to make an AJAX call from within a template to a php script within my templates folder, but I'm getting a 404 from all URLs. Is there a proper way to directly address scripts within PW templates? I've read it will work in the site root, but I'd rather keep all the code together if possible.
    • By Robin S
      An experimental module for adding images to a field via pasting one or more URLs.
      Add Image URLs
      Allows images to be added to an images field by pasting URLs.

      Usage
      Install the Add Image URLs module.
      A "Paste URLs" button will be added to all image fields. Use the button to show a textarea where image URLs may be pasted, one per line. Images are added when the page is saved.
       
      https://github.com/Toutouwai/AddImageUrls
    • By Noel Boss
      Maybe I'm missing something here, but I'm haveing a hard time to get absolute urls if PW is installed in a subdirectory thought the API...
      I need an absolute URL for the backend (as a redirect url of Oauth provider). To build the url i would normaly use
      url()->root.url()->admin – but this results in the install-path beeing present twice;
      domain.com/path/ + path/admin/
      In order to not use $_SERVER['HTTP_HOST'] I fetch the admin page from pages – but this is also not to easy since I need to remove the root folder from path as well. My current solution is somewhat complicated:
      $backendUrl = pages()->get('path="'.str_replace(urls()->root, '', urls()->admin).'", include=all')->httpUrl; The above code seems to be the savest way to get the absolute url to the backend using pure PW API, am I right?
      It would be great if one could fetch absolute urls with something like this
      $backendUrl = urls()->admin->httpUrl // or $backendUrl = httpUrls()->admin  
      SOLVED:
      Thank you @adrian – of course this HAD to be simpler:
      urls()->httpAdmin;  
×
×
  • Create New...