1

I am currently transfering a live website to Craft CMS. I am trying to keep all URLs of pages and images exactly the same as the live version, because of all the pages and images cached in Google. Current URL's are, for example:

http://www.website.com/projects/projectname-1/pictures/picture.jpg

Where projectname-1 and picture.jpg are variable.

In Craft CMS I made a structure called projects. The slug/uri of the entries are setup so that they are the same as the original URL (for example www.website.com/projects/projectname-1)

I made an Asset source with the file system path set as projects/ and asset url as /projects/. When creating an entry within the projects structure, I made it so that when you're adding the images (custom field), it created the subfolder like: projects/{slug}/. The filenames of the images I am uploading are the exact same name as the live version. This all together works, because I am recreating all the same URLs: nice! :)

Now, here comes the problem. I also made a Single for the projects (www.website.com/projects/) page. When I create an index.twig file in craft/templates/projects/index.twig, I get a 404 error when visiting the URL. This is because I also have a folder called projects in my public_html. So, my question is: how do I also show craft/templates/projects/index.twig on my projects Single, while also keeping the original URLs intact (thus at the same time having a /projects/ folder in my public_html).

Hope it makes sense, thanks,

ET

1

This is because the 'projects' folder exists in both public_html and craft/templates, right?

No this simply means that you have no entry with the slug projects as soon as you create an entry with the given slug it will work.

You can also define a route in a config file

'projects ' => 'projects/index.twig',

Generally your template path structure has nothing to do with your url structure. You should define which template should apply for which url route in your CP in the element settings or via config file or plugin

public function registerSiteRoutes()
{
    return array(
        'projects' => 'projects/index.twig'
    );
}
  • Hi, I do have an entry, which is the Single 'Projects'. I basically have a STRUCTURE called Projects, which has all the projects in them and a SINGLE called 'Projects - Overview', which has the 'website.com/projects' URI. The tree basically is: 1. craft/templates/projects/index.twig 2. public_html/projects/projectname/pictures/picture.jpg – remcomu19 Feb 15 '18 at 13:18
  • What happens when you insert the URI projects? Did you make sure your single contains the template value projects/index – Robin Schambach Feb 15 '18 at 13:21
  • (I updated my comment with my tree). Yes, I did make sure the single contains the correct template value. I get a 404. – remcomu19 Feb 15 '18 at 13:22
  • The URI 'website.com/projects/'is still wrong it must be only projects – Robin Schambach Feb 15 '18 at 13:25
  • Excuse me, that is the case. The URI is called projects. – remcomu19 Feb 15 '18 at 13:28
1

https://craftcms.com/docs/routing

  1. Should Craft handle this request in the first place? It’s important to keep in mind that Craft doesn’t actually get involved for every request that touches your server – only requests that go to your index.php file. The .htaccess file that comes with Craft will redirect all would-be 404 requests over to index.php behind the scenes, which is why Craft is able to respond to URLs that don’t point to any actual folder/file in your web root. But if you point your browser directly at a file that does exist (such as a front-end image URL), Apache is going to serve that file directly. Craft won’t be summoned for that.

Lets begin ( i have set up a testenviroment to test all this below ):

You have resources at:

www.website.com/assets/img/projects/{slug}/image.jpg

You want your urls to look like this?

www.website.com/projects/{slug}/image.jpg but this gives you an actual 404

Craft tries to follow all the routing steps, but since your assets setup in the Craft CP isn't a route, it will give you a 404 correct?

When you change the CPfield "url to your folder" from "/projects/" to "/assets/img/projects/" it will give you the file, so my question would be, is craft not pointing back to the "public_html" folder here when your CPfield is set to "/project/"??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.