<p><a href="https://craftcms.com/docs/routing" rel="nofollow noreferrer">https://craftcms.com/docs/routing</a></p>

<blockquote>
  <ol>
  <li>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 <strong>(such as a front-end image URL)</strong>, Apache is going to serve that file directly. Craft won’t be summoned for that.</li>
  </ol>
</blockquote>

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

<p>You have resources at:</p>

<p><code>www.website.com/assets/img/projects/{slug}/image.jpg</code></p>

<p>You want your urls to look like this?</p>

<p><code>www.website.com/projects/{slug}/image.jpg</code> but this gives you an actual <strong>404</strong></p>

<p>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 <strong>404</strong> correct?</p>

<p>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/"??</p>

CC BY-SA 3.0
2018-02-16T12:26:13.167Z
2018-02-16T12:26:13.167Z
Kevon
<blockquote>
  <p>This is because the 'projects' folder exists in both public_html and craft/templates, right?</p>
</blockquote>

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

<p>You can also define a <a href="https://craftcms.com/docs/routing" rel="nofollow noreferrer">route</a> in a <a href="https://craftcms.com/docs/routing#advanced-routing" rel="nofollow noreferrer">config</a> file </p>

<pre><code>'projects ' =&gt; 'projects/index.twig',
</code></pre>

<p>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 <a href="https://craftcms.com/docs/plugins/hooks-reference#registerSiteRoutes" rel="nofollow noreferrer">plugin</a></p>

<pre><code>public function registerSiteRoutes()
{
    return array(
        'projects' =&gt; 'projects/index.twig'
    );
}
</code></pre>

CC BY-SA 3.0
2018-02-15T13:18:22.750Z
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 'http://www.website.com/projects/' URI. The tree basically is:

1. craft/templates/projects/index.twig
2. public_html/projects/projectname/pictures/picture.jpg
remcomu19
CC BY-SA 3.0
2018-02-15T13:21:23.590Z
What happens when you insert the URI `projects`? Did you make sure your single contains the template value `projects/index`
Robin Schambach
CC BY-SA 3.0
2018-02-15T13:22:51.827Z
(I updated my comment with my tree). Yes, I did make sure the single contains the correct template value. I get a 404.
remcomu19
CC BY-SA 3.0
2018-02-15T13:25:18.583Z
The URI `'website.com/projects/'`is still wrong it must be only `projects`
Robin Schambach
CC BY-SA 3.0
2018-02-15T13:28:14.093Z
Excuse me, that is the case. The URI is called projects.
remcomu19
CC BY-SA 3.0
2018-02-15T13:28:53.380Z
Could you tell us the generated frontend URL from Craft when you open the frontend entry from your backend?
Robin Schambach
CC BY-SA 3.0
2018-02-15T13:34:37.147Z
That is http://www.website.com/projects/
remcomu19
CC BY-SA 3.0
2018-02-15T13:39:45.563Z
Seems like you are not in `dev` mode anymore. Maybe you have a bug in your template but Craft won't show template errors in `live` mode and instead show a 404 page.. Could you please make sure you are in dev mode? https://craftcms.com/support/dev-mode
Robin Schambach
CC BY-SA 3.0
2018-02-15T13:41:34.813Z
I am in dev mode: 'devMode' => true
remcomu19
CC BY-SA 3.0
2018-02-15T13:46:57.197Z
Really strange. when you enter a totally different url `/1234567890` do you receive a stack trace? If yes there must be an internal redirect => you have something in your template or a plugin that prevents the page from getting displayed, If not there must be something wrong with your configuration or you did something we don't know about that causes this issue. I never experienced this bug. However you could try to create a custom route with the function I mentioned above
Robin Schambach
CC BY-SA 3.0
2018-02-15T13:53:20.630Z
I'm getting the same 404. It's basically this: think of the standard NEWS section, which comes with a fresh Craft CMS install. It works right out of the box. When I create a folder called news in my public_html, I get a 404. (Let's say I created this in public_html, because my live website has an image URL called http://www.website.com/news/article/image.jpg, which I want to preserve).
remcomu19
CC BY-SA 3.0
2018-02-15T13:58:00.253Z
You should never point template urls to your `public` folder. You public folder should only contain a few files like an `index.php` and the language redirects as well as some assets. All your templates are in your `templates` folder which is `craft/templates` by default. Everything else makes no real sense and you should never point to images directly in your assets folder. You should upload them and use `asset.getUrl()`. I Think the issue is that your did not really understand how Craft works. In most cases your `public` only has an `.htaccess` and a `index.php`
Robin Schambach
CC BY-SA 3.0
2018-02-15T14:02:44.243Z
The folder in the public_html is only there to preserve the original URL. The index template for the /projects/ is still craft/templates/projects/index.twig. Like I stated, my tree is: 1. `craft/templates/projects/index.twig` and 2. `public_html/projects/projectname/pictures/picture.jpg`
remcomu19
CC BY-SA 3.0
2018-02-15T14:05:53.063Z
Yes and I think that causes the error. You should not do that. As soon as your Web Server finds a folder in your `public` folder that represents the same route as your URI it will bypass Craft completely. It should work as soon as you use the system properly. Please rename your `public_html/projects` folder and tell me if your `projects` is available then
Robin Schambach
CC BY-SA 3.0
2018-02-15T14:13:04.187Z
Yes, then it works. I knew that, because I said: **This is because the 'projects' folder exists in both public_html and craft/templates, right?**. But how do I go about preserving the original image URLs? For example: http://www.website.com/projects/projectname/pictures/picture.jpg
remcomu19
CC BY-SA 3.0
2018-02-15T14:19:09.783Z
Ahh ok now I understand what you mean. Well easy thing. Go to `/admin/settings/assets/` and define the url for this source as `/projects/projectname/pictures/` then you'll upload the image as an asset in your cp. sry about the confusion. I never came to the idea you did it that way
Robin Schambach
CC BY-SA 3.0
2018-02-15T14:33:02.017Z
Well.. maybe I'm not understanding correctly, but setting the source as `/projects/projectname/pictures/` is the exact problem I'm having. Because I can't use the `projects` folder in my public_html.
remcomu19
CC BY-SA 3.0
2018-02-15T14:38:37.870Z
only the url. The folder would be something like `assets` so you put your images into `public_html/assets/`
Robin Schambach
CC BY-SA 3.0
2018-02-15T15:33:51.637Z
Ok, this is not working. I'm afraid I might be explaining the problem wrong. Could you please check my original post? I explained more in detail.
remcomu19
CC BY-SA 3.0
2018-02-15T15:39:50.283Z
Like I already said it's not possible the way you try it. Why don't you just create a folder `assets` in your public folder and point to this one. Your asset url will be `/projects/projectname/pictures/` and your asset path will be `assets` or `assets/projects` if you want. You can also use twig in those fields. `{assetPath}/assets/projects` and define an assetPath in your config that points somewhere else. To be honest I don't understand your problem why you want to stick to this not so well thought folder structure
Robin Schambach
CC BY-SA 3.0
2018-02-15T15:54:36.130Z
Maybe you don't understand it but your `path` and your `url` can be totally different. They don't need to be the same. You can insert `public_html/whatever/you/want/` as the path where you want to insert your images and use the url `projects/foo/bar` so when someone enters `project/foo/bar/image.jpg` Craft will grab the asset at `public_html/whatever/you/want/image.jpg`
Robin Schambach
CC BY-SA 3.0
2018-02-16T08:02:53.263Z
Hi Robin, thanks for the help (_.. and patience .. ;_) ). I just tried this. I set the images to be in path `public_html/assets/img/projects/` and entered `/projects/` as the URL. Now, when I make a for loop in the twig template, the URLs (`asset.getUrl()`) are coming out correctly (with `projects`), though when I visit them, I get a 404. The images are loading correctly when visiting with them with the asset path as url (eg. `http://www.website.com/assets/img/projects/projectname/pictures/picture.jpg`), but not with `http://www.website.com/projects/projectname/pictures/picture.jpg`.
remcomu19
CC BY-SA 3.0
2018-02-16T08:34:31.463Z
What happens when you enter (just for now) the full paths and full urls and not just `projects`. Yesterday I had this problem with someone else too. He/she moved his/her files into the `public_html` folder without reconfiguration all his paths/Craft configs that needs to be reconfigured when you move the default Craft `public` folder. However I strongly suggest you to read some documents how to set up a Craft project correctly
Robin Schambach
CC BY-SA 3.0
2018-02-16T09:09:31.600Z
Like I said, the full path works: `http://www.website.com/assets/img/projects/projectname/pictures/picture.jpg`, but the full url not: `http://www.website.com/projects/projectname/pictures/picture.jpg`. The **asset path** is set as `assets/img/projects/` and the **asset URL** is set as `projects/` Also, I did not move the default Craft public folder.. :)
remcomu19
CC BY-SA 3.0
2018-02-16T09:32:27.373Z
I mean you should enter the full path and the full url into your asset source. I'll never ask for "your" paths and the urls you wanted to use before because you should always avoid to do such things. as your url `http://www.website.com/projects/projectname/pictures/` and the path your full server path. Of course you changed the default Craft structure in some way or another because there is no `public_html` folder in Craft it provides a `public` folder (or a web folder in Craft 3). So you must have changed the structure in one way or another. Normally you don't have to take care of it
Robin Schambach
CC BY-SA 3.0
2018-02-16T09:45:38.317Z
I did this and still not working. I set the url as absolute url : `http://www.website.com/projects/projectname/pictures/`, but can't change the asset path to anything other than `assets/img/projects/`, because otherwise I get an error doing ***update asset indexes***, saying the path does not exist.
remcomu19
CC BY-SA 3.0
2018-02-15T13:02:20.550Z
2018-02-15T13:02:20.550Z
Robin Schambach
<p>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:</p>

<p><a href="http://www.website.com/projects/projectname-1/pictures/picture.jpg" rel="nofollow noreferrer">http://www.website.com/projects/projectname-1/pictures/picture.jpg</a></p>

<p>Where <strong>projectname-1</strong> and <strong>picture.jpg</strong> are variable.</p>

<p>In Craft CMS I made a <strong>structure</strong> called <strong>projects</strong>. 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)</p>

<p>I made an Asset source with the file system path set as <strong>projects/</strong> and asset url as <strong>/projects/</strong>. 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! :)</p>

<p>Now, here comes the problem. I also made a <strong>Single</strong> 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. <strong>This is because I also have a folder called projects in my public_html.</strong> 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).</p>

<p>Hope it makes sense, thanks,</p>

<p>ET</p>

<templating><url><404>
404 error if folder in public_html has same name as folder in craft/templates
# 404 error if folder in public_html has same name as folder in craft/templates

(Asked by: username_0 on 2018-02-15)

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

**Tags:** templating, url, 404

---

## 2 answers

### Answer by username_1 on 2018-02-16. Score: 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/"??


---

### Answer by username_2 on 2018-02-15. Score: 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'
    );
}

> **Comments:**
> **username_0**: 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 'http://www.website.com/projects/' URI. The tree basically is:  1. craft/templates/projects/index.twig 2. public_html/projects/projectname/pictures/picture.jpg  
> **username_2**: What happens when you insert the URI `projects`? Did you make sure your single contains the template value `projects/index`  
> **username_0**: (I updated my comment with my tree). Yes, I did make sure the single contains the correct template value. I get a 404.  
> **username_2**: The URI `'website.com/projects/'`is still wrong it must be only `projects`  
> **username_0**: Excuse me, that is the case. The URI is called projects.  
> **username_2**: Could you tell us the generated frontend URL from Craft when you open the frontend entry from your backend?  
> **username_0**: That is http://www.website.com/projects/  
> **username_2**: Seems like you are not in `dev` mode anymore. Maybe you have a bug in your template but Craft won't show template errors in `live` mode and instead show a 404 page.. Could you please make sure you are in dev mode? https://craftcms.com/support/dev-mode  
> **username_0**: I am in dev mode: 'devMode' => true  
> **username_2**: Really strange. when you enter a totally different url `/1234567890` do you receive a stack trace? If yes there must be an internal redirect => you have something in your template or a plugin that prevents the page from getting displayed, If not there must be something wrong with your configuration or you did something we don't know about that causes this issue. I never experienced this bug. However you could try to create a custom route with the function I mentioned above  
> **username_0**: I'm getting the same 404. It's basically this: think of the standard NEWS section, which comes with a fresh Craft CMS install. It works right out of the box. When I create a folder called news in my public_html, I get a 404. (Let's say I created this in public_html, because my live website has an image URL called http://www.website.com/news/article/image.jpg, which I want to preserve).  
> **username_2**: You should never point template urls to your `public` folder. You public folder should only contain a few files like an `index.php` and the language redirects as well as some assets. All your templates are in your `templates` folder which is `craft/templates` by default. Everything else makes no real sense and you should never point to images directly in your assets folder. You should upload them and use `asset.getUrl()`. I Think the issue is that your did not really understand how Craft works. In most cases your `public` only has an `.htaccess` and a `index.php`  
> **username_0**: The folder in the public_html is only there to preserve the original URL. The index template for the /projects/ is still craft/templates/projects/index.twig. Like I stated, my tree is: 1. `craft/templates/projects/index.twig` and 2. `public_html/projects/projectname/pictures/picture.jpg`  
> **username_2**: Yes and I think that causes the error. You should not do that. As soon as your Web Server finds a folder in your `public` folder that represents the same route as your URI it will bypass Craft completely. It should work as soon as you use the system properly. Please rename your `public_html/projects` folder and tell me if your `projects` is available then  
> **username_0**: Yes, then it works. I knew that, because I said: **This is because the 'projects' folder exists in both public_html and craft/templates, right?**. But how do I go about preserving the original image URLs? For example: http://www.website.com/projects/projectname/pictures/picture.jpg  
> **username_2**: Ahh ok now I understand what you mean. Well easy thing. Go to `/admin/settings/assets/` and define the url for this source as `/projects/projectname/pictures/` then you'll upload the image as an asset in your cp. sry about the confusion. I never came to the idea you did it that way  
> **username_0**: Well.. maybe I'm not understanding correctly, but setting the source as `/projects/projectname/pictures/` is the exact problem I'm having. Because I can't use the `projects` folder in my public_html.  
> **username_2**: only the url. The folder would be something like `assets` so you put your images into `public_html/assets/`  
> **username_0**: Ok, this is not working. I'm afraid I might be explaining the problem wrong. Could you please check my original post? I explained more in detail.  
> **username_2**: Like I already said it's not possible the way you try it. Why don't you just create a folder `assets` in your public folder and point to this one. Your asset url will be `/projects/projectname/pictures/` and your asset path will be `assets` or `assets/projects` if you want. You can also use twig in those fields. `{assetPath}/assets/projects` and define an assetPath in your config that points somewhere else. To be honest I don't understand your problem why you want to stick to this not so well thought folder structure  
> **username_2**: Maybe you don't understand it but your `path` and your `url` can be totally different. They don't need to be the same. You can insert `public_html/whatever/you/want/` as the path where you want to insert your images and use the url `projects/foo/bar` so when someone enters `project/foo/bar/image.jpg` Craft will grab the asset at `public_html/whatever/you/want/image.jpg`  
> **username_0**: Hi Robin, thanks for the help (_.. and patience .. ;_) ). I just tried this. I set the images to be in path `public_html/assets/img/projects/` and entered `/projects/` as the URL. Now, when I make a for loop in the twig template, the URLs (`asset.getUrl()`) are coming out correctly (with `projects`), though when I visit them, I get a 404. The images are loading correctly when visiting with them with the asset path as url (eg. `http://www.website.com/assets/img/projects/projectname/pictures/picture.jpg`), but not with `http://www.website.com/projects/projectname/pictures/picture.jpg`.  
> **username_2**: What happens when you enter (just for now) the full paths and full urls and not just `projects`. Yesterday I had this problem with someone else too. He/she moved his/her files into the `public_html` folder without reconfiguration all his paths/Craft configs that needs to be reconfigured when you move the default Craft `public` folder. However I strongly suggest you to read some documents how to set up a Craft project correctly  
> **username_0**: Like I said, the full path works: `http://www.website.com/assets/img/projects/projectname/pictures/picture.jpg`, but the full url not: `http://www.website.com/projects/projectname/pictures/picture.jpg`. The **asset path** is set as `assets/img/projects/` and the **asset URL** is set as `projects/` Also, I did not move the default Craft public folder.. :)  
> **username_2**: I mean you should enter the full path and the full url into your asset source. I'll never ask for "your" paths and the urls you wanted to use before because you should always avoid to do such things. as your url `http://www.website.com/projects/projectname/pictures/` and the path your full server path. Of course you changed the default Craft structure in some way or another because there is no `public_html` folder in Craft it provides a `public` folder (or a web folder in Craft 3). So you must have changed the structure in one way or another. Normally you don't have to take care of it  
> **username_0**: I did this and still not working. I set the url as absolute url : `http://www.website.com/projects/projectname/pictures/`, but can't change the asset path to anything other than `assets/img/projects/`, because otherwise I get an error doing ***update asset indexes***, saying the path does not exist.  

---

