Jump to content

How to change image/file/template path?


tires
 Share

Recommended Posts

Hello once again!

I wonder if i can change the path (or folder) to the image/file directory?

So that the url of my uploaded image in the sourcecode is not the default "site/assets/files/1234/myimage.jpg" but something like ""myprettyshortpath/myimage.jpg".

And how about the path to the template directory?

Can i change this for example from the dafault "site/templates/styles/style.css" to "styles/style.css"?

Many thanks and best regards!!!

Link to comment
Share on other sites

It's not suggested to change any paths, but you can use all the config variables here http://cheatsheet.processwire.com/#config (the url ones) to make the urls for template files more descriptive. Regarding the file fields: You'll not have the need to write those urls, as these are dynamic anyway. Just use the api to get the urls: 

$page->files->first()->url;
  • Like 1
Link to comment
Share on other sites

Ok, so to make the template path to "www.domain.com/tpl" i have to write something like:

$config->urls->templates = "/tpl";

Is that right?
Where do i have to insert this code?

Concerning the imagepath, i know that i don't have to write the path on my own. But i want the img-tag to look like this:

<img src="images/myimage.jpg" />

Is this possible?

Many thanks and best regards!

Link to comment
Share on other sites

You got this a little bit wrong: The $config urls are not there to set something, they just get you the url, so you don't need to write it (and it's more prove to changes, even if they aren't likely). It's not shorter, but you can just care about the path relative to the templates folder. 

<link rel="stylesheet" type="text/css" href="site/templates/styles/style.css">
<!-- becomes this -->
<link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates; ?>styles/style.css">

Your proposed images path won't be possible as files are saved in page-specific folders, therefore the page's id as one folder. Otherwise you can't have two pages with files named the same. This is a needed behavior to make file uploads scale as well as everything else in ProcessWire.

To elaborate more about why it's not a suggested idea to move these locations around:

- Everything outside of the site/ folder is part of the processwire core and is therefore not save from potential updates. Therefore anything specific to your site should be inside this folder. It's save there and additionally easily moved to another installation and easy to backup without adding the cms files itself. 

- The .htaccess file does incorporate quite a few rules (depending on the location of files) to make it as secure as it is. 

- There's an option to secure files of hidden / unpublished pages from direct access, which is dependent on the path files are stored in.

- There's an option to have images distributed over multiple folders, so it scales even beyond some filesystem limitations (only needed for sites with thousands of pages, but still), which is also dependent on a fixed location.

- The folder structure make a lot of sense, even if it may seem verbose if one looks only at the single entity "uploaded files".

  • Like 1
Link to comment
Share on other sites

Thank you for your detailed answer!!!

Is there a way to just change the url in the imagetag without changing the real filepath?

Also for SEO reasons i would like to have it a bit like this:

<img src="images/holiday/locations/newyork.jpg" />
Link to comment
Share on other sites

Thank you for your detailed answer!!!

Is there a way to just change the url in the imagetag without changing the real filepath?

Also for SEO reasons i would like to have it a bit like this:

<img src="images/holiday/locations/newyork.jpg" />

I am not an SEO guru, but is the path to an image something that is actually considered? Have a quick read here: http://webmasters.stackexchange.com/questions/36434/what-should-filenames-and-urls-of-images-contain-for-seo-benefit

You might find this module useful: http://modules.processwire.com/modules/process-custom-upload-names/

It allows you to automatically rename files/images as they are uploaded - you can make use all sorts of PW variables to define the scheme for the new name.

Link to comment
Share on other sites

To your question: It would certainly be possible to route your urls to the default paths. But as long as you'd need php for this routing it would introduce additional overhead to images, which already are the big bottleneck of websites just by file size. I don't know if you could do this by .htaccess rewrites only. Should really depend on how flexible it should be. 

With php involved you could for example use the urlSegments to make images available as part of the page they are on, where the base url is the page's url and the trailing filename would be evaluated as urlSegment.

Link to comment
Share on other sites

Thanks for your answers!

I am not an htaccess expert, but i also considered this way.

Did you have some experience wiith this?

With php involved you could for example use the urlSegments to make images available as part of the page they are on, where the base url is the page's url and the trailing filename would be evaluated as urlSegment.

I don't understand this part.

I see the urlSegments output the parts of the url.

Should i set the image path as base url?

Do i have to output the image path via urlSegments?

Could you explain this approach?

Thanks a lot and best regards!

Link to comment
Share on other sites

The urlSegment way would work like this:

www.example.com/url/to/page/filename.jpg

There the "filename.jpg" is the url segment and you could output/return the right file in the template of the page, in this case the one under "/url/to/page/". 

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