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?

  • You linked us to the init function... what are we supposed to be looking at? Confused. Jan 27 '15 at 15:53
  • 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
    Jan 27 '15 at 15:58
  • 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. Jan 27 '15 at 16:25
  • I think it's not so much multiple locale subfolders in the webroot as it is multiple webroots. Jan 27 '15 at 17:21

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.

  1. Put all of your locale subfolders into a single folder, called locales for example. So your directory structure would be:

  2. Make sure you update the craft path in each locale's index.php file accordingly:

    $craftPath = '../../../craft';
  3. 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]
  • 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? Jan 31 '15 at 7:44
  • can you post your code somewhere so i can review it?
    – Ben Croker
    Jan 31 '15 at 22:33

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.