Jump to content

Set different folder for "site/assets/files/"?


donatas
 Share

Recommended Posts

Hi,

I am trying (wondering if even possible) to set a very different file folder path for my PW install. The path I want to set exist in the same server, but in another domain. Can the PW API see that far into file system? It is a shared hosting environment so no permission management options available.

Also can this be achieved through .htaccess redirection? If you request a file (images mostly, but translation json files are important too) from `domain-A.com/site/assets/files/` to grab them from `domain-B.com/site/assets/files/`? I would prefer to do this through PW API, I can see the function `$config->setPath()` but it didn't work when set in  config.php like `$config->setPath("files", "/domains/domain-B/public_html/site/assets/files/")`.

Is there some other option to do this?

My ultimate goal is to have two PW installs on different domains but one is just a "mirror" that is using the same database as the other and should use the same files structure if editors upload any images to the main (domain-B.com) website. I could use domain parking function but it then needs a more expensive SSL certificate for two domains , which I am trying to avoid if possible ? (I'd like to use single domain Let's Encrypt certificates, thus I need to PW installs).

Would appreciate any insight! Thanks!

Link to comment
Share on other sites

I had a different setup where I wanted my files served from a sub-domain (even though in the end it was from /site/assets/files), but it's somehow related.

What I did was to point the sub-domain to /site/assets/files, and then add this hook in ready.php :

$wire->addHookAfter("Pagefile::url", function($event) {
	static $n = 0;
	if(++$n === 1) {
		$file = $event->object;
		$url = $file->httpUrl;
		$host = wire("config")->httpHost;
		$url = str_replace("$host/site/assets/files", "sub.domain.com", $url);
		$event->return = $url;
	}
	$n--;
});

You could replace "sub.domain.com" to "domainB.com/site/assets/files" (or even clear the "site/assets/files" part in your case).

Hope it helps !

  • Like 4
Link to comment
Share on other sites

Thanks, @monollonom, that actually did it! I am very grateful for your tip.

Now only to make translation .json files to be shared like that too as this is multilanguage site.. They are saved in the same /site/assets/files/ directory, but your shared hook doesn't seem to affect them. I wonder if there is a way. Probably need to hook to a different event related to translation saving in the admin.

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