$config->setUrl() method

Change or set just the URL for the named location (leaving server disk path as-is)

  • If you want to update both disk path and URL at the same time, or if URL and path are going to be the same relative to installation root, use the setLocation() method instead.

  • Paths relative to PW installation root should omit the leading slash, i.e. use site/templates/ and NOT /site/templates/.

  • The $for argument can be: cache, logs, files, tmp, templates, or one of your own. Other named locations may also work, but since they can potentially be used before PW’s “ready” state, they may not be reliable.

  • Warning: anything that changes a system URL may make the URL no longer have the protection of the root .htaccess file. As a result, if you modify system URLs for anything on a live server, you should also update your .htaccess file to reflect your changes (while leaving existing rules for original URL in place).

The following examples would go in /site/ready.php.

Let’s say we created a symbolic link in our web root /tiedostot/ (Finnish for “files”) that points to /site/assets/files/. We want all of our file URLs to appear as “/tiedostot/1234/img.jpg” rather than “/site/assets/files/1234/img.jpg”. We would change the URL for ProcessWire’s $config->urls->files to point there like this example below. (Please also see warning above)

In this next example, we are changing all of our file URLs on the front-end to point a cookieless subdomain that maps all requests to the root path of https://files.domain.com to /site/assets/files/. The example works for CDNs as well.

Available since version 3.0.141.

Examples

if($page->template != 'admin') {
  $config->setUrl('files', 'tiedostot/');
}
if($page->template != 'admin) {
  $config->setUrl('files', 'https://files.domain.com/');
}

Usage

$self = $config->setUrl(string $for, string $url);

Arguments

NameType(s)Description
forstring

Named location from $config->urls, one of: cache, logs, files, tmp, templates, or your own.

urlstring

URL relative to PW installation root (no leading slash) or absolute URL if not (optionally including scheme and domain).

Return value

self

Exceptions

Method can throw exceptions on error:

  • WireException


$config methods and properties

API reference based on ProcessWire core version 3.0.155

Twitter updates

  • This post covers a few of the bigger updates in ProcessWire 3.0.154+3.0.155. This includes new live replacement of text in core and modules, a new method for creating canonical URLs, and some major upgrades to our input->urlSegment() method! More
    24 April 2020
  • A brief look at what's new in ProcessWire 3.0.154 in this forum post: More
    17 April 2020
  • This week we’ve got a few new and interesting core updates in progress, though none quite ready to release just yet. So rather than releasing version 3.0.154 today, I thought we'd instead take a brief look at what’s coming over the next few weeks… More
    3 April 2020

Latest news

  • ProcessWire Weekly #310
    The 310th issue of ProcessWire Weekly is going to be short and sweet: in this issue we'll walk you through the latest core updates, introduce a third party module called Twack, and check out a really gorgeous new site of the week. Read on!
    Weekly.pw / 18 April 2020
  • ProcessWire 3.0.154 and 3.0.155 core updates
    This post covers a few of the bigger updates in ProcessWire 3.0.154 and 3.0.155 on the dev branch. This includes a new function for live replacement of text in core and modules, a new method for creating canonical URLs, and some major upgrades to our $input->urlSegment() method that I think you’ll like!
    Blog / 24 April 2020
  • Subscribe to weekly ProcessWire news

“Yesterday I sent the client a short documentation for their ProcessWire-powered website. Today all features already used with no questions. #cmsdoneright—Marc Hinse, Web designer/developer