<p>I'm not exactly sure what you are trying to achieve, but here is a way to have unlimited locales with only a single subfolder in your public root directory.</p>

<ol>
<li><p>Put all of your locale subfolders into a single folder, called <code>locales</code> for example. So your directory structure would be:</p>

<pre><code>public/locales/de/
public/locales/es/
public/locales/fr/
</code></pre></li>
<li><p>Make sure you update the craft path in each locale's <code>index.php</code> file accordingly:</p>

<pre><code>$craftPath = '../../../craft';
</code></pre></li>
<li><p>Then you just need the following code in your root <code>.htaccess</code> file to redirect to the appropriate subfolder:</p>

<pre><code># Redirect locales
RewriteCond %{REQUEST_URI} ^/(de|es|fr)/ [NC]
RewriteRule (.+) /locales/$1 [QSA,L]
</code></pre></li>
</ol>

CC BY-SA 3.0
2015-01-31T07:44:25.800Z
Drats. This folder arrangement sounded great, but didn't work for me. I moved the language folders (en|th|zh) into a /locales/ directory, changed $craftPath in each index.php, modified the .htaccess file with this code (changed to reflect the relevant language codes) — but it didn't work. I just get a "The requested URL was not found on this server" error. As far as I know the rewrite engine is working fine. Any idea what might be going wrong here?
Andrew Macpherson
CC BY-SA 3.0
2015-01-31T22:33:25.697Z
can you post your code somewhere so i can review it?
Ben Croker
CC BY-SA 3.0
2015-01-27T19:41:49.133Z
2015-01-27T19:41:49.133Z
Ben Croker
<p>Would it be possible to have a cleaner site setup without all those 'locale' subfolders in the webroot? Somehow it looks like there's something similar already done here (<a href="https://github.com/craftcms/cms/tree/master-v2/src/services/HttpRequestService.php#L99" rel="nofollow noreferrer">https://github.com/craftcms/cms/tree/master-v2/src/services/HttpRequestService.php#L99</a>) if I'm not wrong, wouldn't it be nicer to also just remove the locale if one is detected?</p>

<p>Bonus question :) :
Where in the hell is the actual Entry Slug -> Template resolving done? I know there's a lot of stuff happening with filters, action and resource requests. The closest I could get is that here the template/render controller gets triggered (<a href="https://github.com/craftcms/cms/tree/master-v2/src/framework/web/CWebApplication.php#L274" rel="nofollow noreferrer">https://github.com/craftcms/cms/tree/master-v2/src/framework/web/CWebApplication.php#L274</a>) which in the end resolves to the action render method in the TemplatesController (<a href="https://github.com/craftcms/cms/tree/master-v2/src/controllers/TemplatesController.php#L50" rel="nofollow noreferrer">https://github.com/craftcms/cms/tree/master-v2/src/controllers/TemplatesController.php#L50</a>), already with the correct $template parameter set. </p>

<p>Could someone guide me in a direction here? </p>

CC BY-SA 3.0
2015-01-27T15:53:02.757Z
You linked us to the `init` function... what are we supposed to be looking at? Confused.
Douglas McDonald
CC BY-SA 3.0
2015-01-27T15:58:41.017Z
What's the problem with `/webroot/en/index.php` being responsible for `http://example.com/en`? And why should the folder (incl. `index.php`) be removed, if the locale is detected?
carlcs
CC BY-SA 3.0
2015-01-27T16:25:40.777Z
ah sorry, I meant to link to line 130 where they shift the _segments array to remove the 'admin' part of the url. I think something similar could be done with the locales.

And I don't want to remove the folder, I want to shift the _segments array to remove the locale-segment from the url and set the current craft locale. Like that there would be no need to just copy paste the index.php in several different folders.
Sidney Widmer
CC BY-SA 3.0
2015-01-27T17:21:23.870Z
I think it's not so much *multiple locale subfolders in the webroot* as it is multiple webroots.
Marion Newlevant
<localization><multi-environment><routing>
Multi-lingual site without subfolders
# Multi-lingual site without subfolders

(Asked by: username_0 on 2015-01-27)

Would it be possible to have a cleaner site setup without all those 'locale' subfolders in the webroot? Somehow it looks like there's something similar already done here (<https://github.com/craftcms/cms/tree/master-v2/src/services/HttpRequestService.php#L99>) if I'm not wrong, wouldn't it be nicer to also just remove the locale if one is detected?

Bonus question :) :
Where in the hell is the actual Entry Slug -> Template resolving done? I know there's a lot of stuff happening with filters, action and resource requests. The closest I could get is that here the template/render controller gets triggered (<https://github.com/craftcms/cms/tree/master-v2/src/framework/web/CWebApplication.php#L274>) which in the end resolves to the action render method in the TemplatesController (<https://github.com/craftcms/cms/tree/master-v2/src/controllers/TemplatesController.php#L50>), already with the correct $template parameter set.

Could someone guide me in a direction here?

**Tags:** localization, multi-environment, routing

> **Comments:**
> **username_1**: You linked us to the `init` function... what are we supposed to be looking at? Confused.  
> **username_2**: What's the problem with `/webroot/en/index.php` being responsible for `http://example.com/en`? And why should the folder (incl. `index.php`) be removed, if the locale is detected?  
> **username_0**: ah sorry, I meant to link to line 130 where they shift the _segments array to remove the 'admin' part of the url. I think something similar could be done with the locales.  And I don't want to remove the folder, I want to shift the _segments array to remove the locale-segment from the url and set the current craft locale. Like that there would be no need to just copy paste the index.php in several different folders.  
> **username_3**: I think it's not so much *multiple locale subfolders in the webroot* as it is multiple webroots.  

---

## 1 answers

### Answer by username_4 on 2015-01-27. Score: 2

I'm not exactly sure what you are trying to achieve, but here is a way to have unlimited locales with only a single subfolder in your public root directory.

Put all of your locale subfolders into a single folder, called locales for example. So your directory structure would be:
public/locales/de/
public/locales/es/
public/locales/fr/

Make sure you update the craft path in each locale's index.php file accordingly:
$craftPath = '../../../craft';

Then you just need the following code in your root .htaccess file to redirect to the appropriate subfolder:
# Redirect locales
RewriteCond %{REQUEST_URI} ^/(de|es|fr)/ [NC]
RewriteRule (.+) /locales/$1 [QSA,L]

> **Comments:**
> **username_5**: Drats. This folder arrangement sounded great, but didn't work for me. I moved the language folders (en|th|zh) into a /locales/ directory, changed $craftPath in each index.php, modified the .htaccess file with this code (changed to reflect the relevant language codes) — but it didn't work. I just get a "The requested URL was not found on this server" error. As far as I know the rewrite engine is working fine. Any idea what might be going wrong here?  
> **username_4**: can you post your code somewhere so i can review it?  

---

