Jump to content

Install PW in a folder


arjen
 Share

Recommended Posts

Hi,

Just launched a website with PW. Pretty cool work as usual. Followed the logic provided by Ryan in his Blog Profile and it seems to be a more logical and structural approach. Thanks for that. The problem is that the website is showing the folder name in it's paths.

I did the following:

I installed the site in a folder inside the public_html. So the path is: /user/public_html/annemieboer.nl/index.php. I added a rewrite in the /public_html/.htaccess with the following contents:

RewriteCond %{HTTP_HOST}    ^www.annemieboer.nl$
RewriteCond %{REQUEST_URI}  !^/annemieboer.nl/
RewriteRule (.*)	  /annemieboer.nl/$1 [last]
RewriteCond %{HTTP_HOST}    ^annemieboer.nl$
RewriteCond %{REQUEST_URI}  !^/annemieboer.nl/
RewriteRule (.*)	  /annemieboer.nl/$1 [last]

But now the urls are like http://annemieboer.nl/annemieboer.nl/contact/. I've tried several stuff like editing the RewriteBase and FollowSymLinks. I don't really know what I'm doing there, so that didn't help me.

I know I can fix this using vhosts but since this is shared hosting I can't touch those. The reason for me to put it in a folder is because it runs multiple sites.

Any ideas using .htaccess to fix this?

Link to comment
Share on other sites

SInce you have it in a subfolder PW will include it in url generated for pages.

To modify the url PW spits out you could create a simple module to the Page:path

This will work for also links in tinymce and $page->url would spit out the right url in your case, so no code changes in your templates. Although you could.

A module like the HelloWorld.module can be taken and add this stuff. The module is autoload so will always replace the path, backend and frontend.

In the init add a hook:

public function init(){
 $this->addHookAfter('Page::path', $this, 'replacePath');
}

In add a method replacePath:

public function replacePath(HookEvent $event) {
 // url generated by PW
 $old = $event->return;
 // strip out the subfolder
 $new = str_replace("/annemieboer.nl", "", $old);
 // return new path
 $event->return = $new;
}

Install it and see if it works as it should everywhere. Tinymce links, page fields and selects.

  • Like 1
Link to comment
Share on other sites

Thanks for the detailed explanation. It seems the folder name isn't in de $event-return variable. It I echo $event->return (see code below) it didn't return the folder title, but the page name like /contact or /over-mij. Where does ProcessWire include the path? Maybe I can str_replace something there?

public function replacePath(HookEvent $event) {
  echo $event->return;

}
Link to comment
Share on other sites

Well, sorry wasn't sure as I didn't try.

Had a quick look again, and "path" isn't returning the subfolder. It's the "url" method that is calling "path" and is appending the root, which would be the subfolder. Since "url" isn't hookable you could either:

1. Use $page->path in all your templates

2. Modify the config->root to not add the subfolder. So Instead of the replacement do only: $this->config->urls->root = "/"; in the hook.

3. Wait for Ryan.

Not sure what will break, since you're excluding the hard subfolder path.

Link to comment
Share on other sites

1. What is running in the root folder of the domain? If it's also ProcessWire, you might want to use one of the multi-site support options.

2. You could try modifying $config->urls->root at the top of your template file (like Soma suggested):

$config->urls->root = '/';

You'll also want to setup these two symlinks in your web root:

/site/ => /annemieboer.nl/site/
/wire/ => /annemieboer.nl/wire/

I haven't tried this, so keep an eye out for adverse effects.

3. I think option 2 would be the simplest. But if for some reason that doesn't work, another option would be to hook Page::render. AdminBar is a good example of a module that does this.

public function ready() {
 if($this->page->template != 'admin') $this->addHookAfter('Page::render', $this, 'hookPageRender'); 
}

public function hookPageRender(HookEvent $event) {
 $event->return = str_replace('/annemieboer.nl/', '/', $event->return); 
}

If you went this route, you'd still want to setup the symlinks I mentioned above.

Link to comment
Share on other sites

Thans guys! I included

$config->urls->root = '/';

at the top of my main.inc template. Then I changed

$page->path;

to

$page->url;

and it seems to work fine. I didn't have to use symlinks, since the paths are accessible at '/'.

  • Like 1
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...