<p>When you are following the <em>each-locale-gets-its-own-index.php-file</em> pattern as outlined in the official KB article, “<a href="http://buildwithcraft.com/help/localization" rel="nofollow">How do I show localized content on the front end?</a>”, then you do <em><strong>not</strong></em> need to include the locale ID in your sections’ Entry URL Format settings.</p>

<p>For example if you have a News section, and you want Arabic entries to get URLs that look like:</p>

<pre><code>http://www.site.com/ar/news/my-entry-slug
</code></pre>

<p>Then the Arabic Entry URL Format should just be this:</p>

<pre><code>news/{slug}
</code></pre>

<p><strong>not</strong> this:</p>

<pre><code>ar/news/{slug}
</code></pre>

<p>Everything leading up to “news/{slug}”, including “ar/”, is handled by your Arabic site URL, as defined in your config/general.php file’s <code>siteUrl</code> setting:</p>

<pre><code>'siteUrl' =&gt; array(
    'en' =&gt; 'http://www.site.com/',
    'ar' =&gt; 'http://www.site.com/ar/',
    // ...
),
</code></pre>

CC BY-SA 3.0
2014-07-10T00:23:55.697Z
I think we posted an answer at the same time...
Andrea DeMers
CC BY-SA 3.0
2014-07-10T00:24:01.290Z
Thanks Brandon, I thought as much but couldn't see it documented anywhere.

Is there any advantage to using one approach over another? I know that some elements of the site (such as my news feed) won't be translated so is craft able to fall back to a master local if there isn't a version in the users preferred local available?

I was also hoping to take a guess at the users local from their ip address and redirect them to the site for their language.
Darren
CC BY-SA 3.0
2014-07-10T00:25:56.627Z
@AndreaDeMers SE says I beat you by 16 minutes :)
Brandon Kelly
CC BY-SA 3.0
2014-07-10T00:27:41.577Z
@user2556299 Which approaches are you referring to? The way outlined above is what pretty much everyone has done to date, that I know of.  As for your other question – probably best to ask that as a separate question as the answer will be pretty involved.
Brandon Kelly
CC BY-SA 3.0
2014-07-10T00:32:16.313Z
I was refering to specifying the url in each section per local in craft over using the php method and specifying the local via PHP - obviously the php way seems less effort but I don't really understand why it is in the CMS if everyone just uses the the PHP override.
Darren
CC BY-SA 3.0
2014-07-10T00:35:26.667Z
The Entry URL Format setting is locale-specific in case the path should actually be translated depending on the locale. I.e. if you have a News section, you might want that to be `news/{slug}` for the English site, and `noticias/{slug}` for the Spanish site.
Brandon Kelly
CC BY-SA 3.0
2014-07-10T00:04:21.160Z
2014-07-10T00:04:21.160Z
Brandon Kelly
<p>When you write:</p>

<blockquote>
  <p>I've had the most luck with this nginx config, together with specifying the local in the section urls in the cms for each section.</p>
</blockquote>

<p>Are you referring to:</p>

<p><img src="https://i.sstatic.net/w4ill.png" alt="enter image description here"></p>

<p>?</p>

<p>If so, and you put the locale, in this case: <code>fr_ca/a-apropos</code>, try removing <code>fr_ca</code>.</p>

CC BY-SA 3.0
2014-07-10T00:20:22.033Z
2014-07-10T00:20:22.033Z
Andrea DeMers
<p>I'm trying to get a basic locals sub directory system working on Nginx:</p>

<p>/entry - en local.
/fr/entry - french translation.
/it/entry ect..</p>

<p>Having read <a href="https://craftcms.stackexchange.com/questions/425/how-do-i-get-the-right-entry-data-based-on-locale-and-slug?rq=1">this knowledge base article</a> and some other forum posts I'm still having difficulties with 404 errors when following them or duplicate '/fr/fr'/entry issues.</p>

<p>Do I need to use duplicate index.php files with locals declared in them if I'm adding url paths in the section admin pages? What about site baseUrls in the config file?</p>

<p>The documentation seems very conflicting in these cases and having tried nearly every possible configuration option my site still won't serve up different locals.</p>

<p>I've had the most luck with this nginx config, together with specifying the local in the section urls in the cms for each section.</p>

<pre><code>server {
    listen 80;
    server_name site.com;
    root /sites/site/public;
    index index.php;
    client_max_body_size 30M;
    location /en/ {
            root /sites/site/public;
            if (!-e $request_filename) {
                    rewrite ^/(.*)$ /index.php?q=$1 last;
            }
    }
    location /ru/ {
            root /sites/site/public/ru;
            if (!-e $request_filename) {
                    rewrite ^/(.*)$ /ru/index.php?q=$1 last;
            }
    }
    location /zh/ {
            root /sites/site/public/zh;
            if (!-e $request_filename) {
                    rewrite ^/(.*)$ /zh/index.php?q=$1 last;
            }
    }
    location / {
            root /sites/site/public;
            if (!-e $request_filename) {
                    rewrite ^/(.*)$ /index.php?q=$1 last;
            }
    }
    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_ignore_client_abort on;
            fastcgi_param  SERVER_NAME $http_host;
    }

    location ~ /\.ht {
            deny  all;
    }
}
</code></pre>

<p>(each index.php has its own set local var within it like so for fr):</p>

<pre><code>// Path to your craft/ folder
$craftPath = '../../craft';

// Tell Craft to serve the local site
define('CRAFT_LOCALE', 'fr');

// Do not edit below this line
</code></pre>

<p>My General config is</p>

<pre><code>&lt;?php

/**
 * General Configuration
 */

return array(
    'siteUrl' =&gt; array(
        'en' =&gt; 'http://www.site.com/',
        'ar' =&gt; 'http://www.site.com/ar/',
        'es' =&gt; 'http://www.site.com/es/',
        'fr' =&gt; 'http://www.site.com/fr/',
        'hu' =&gt; 'http://www.site.com/hu/',
        'it' =&gt; 'http://www.site.com/it/',
        'ru' =&gt; 'http://www.site.com/ru/',
        'zh' =&gt; 'http://www.site.com/zh/',
    ),
    'maxUploadFileSize' =&gt; 2147483647,

    );
</code></pre>

<p>This results in the server displaying the correct links to my localised articles in the menu and the en language serves up entries correctly, however other languages are found at /local/local/entitypath not local/entitypath.</p>

<p>Adding site_urls to my config seems to break things more, causing locals to not be served up at all.</p>

CC BY-SA 3.0
2014-07-08T22:40:35.420Z
As per http://buildwithcraft.com/help/localization, what do you have in /craft/config/general.php and /ru/index.php, /zh/index.php etc files?
Andrea DeMers
CC BY-SA 3.0
2014-07-09T23:27:09.763Z
Sorry, updated with more information, thanks.
Darren
CC BY-SA 3.0
2014-08-20T15:30:24.147Z
Hi @user2556299! Would you mind accepting the answer that ended up being the most helpful? If there hasn't been an answer that solved your problem, it might help to update your question.
Matt Stein
<localization>
Locales sub directories on Nginx
# Locales sub directories on Nginx

(Asked by: username_0 on 2014-07-07)

I'm trying to get a basic locals sub directory system working on Nginx:
/entry - en local.
/fr/entry - french translation.
/it/entry ect..
Having read this knowledge base article and some other forum posts I'm still having difficulties with 404 errors when following them or duplicate '/fr/fr'/entry issues.
Do I need to use duplicate index.php files with locals declared in them if I'm adding url paths in the section admin pages? What about site baseUrls in the config file?
The documentation seems very conflicting in these cases and having tried nearly every possible configuration option my site still won't serve up different locals.
I've had the most luck with this nginx config, together with specifying the local in the section urls in the cms for each section.
server {
    listen 80;
    server_name site.com;
    root /sites/site/public;
    index index.php;
    client_max_body_size 30M;
    location /en/ {
            root /sites/site/public;
            if (!-e $request_filename) {
                    rewrite ^/(.*)$ /index.php?q=$1 last;
            }
    }
    location /ru/ {
            root /sites/site/public/ru;
            if (!-e $request_filename) {
                    rewrite ^/(.*)$ /ru/index.php?q=$1 last;
            }
    }
    location /zh/ {
            root /sites/site/public/zh;
            if (!-e $request_filename) {
                    rewrite ^/(.*)$ /zh/index.php?q=$1 last;
            }
    }
    location / {
            root /sites/site/public;
            if (!-e $request_filename) {
                    rewrite ^/(.*)$ /index.php?q=$1 last;
            }
    }
    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_ignore_client_abort on;
            fastcgi_param  SERVER_NAME $http_host;
    }

    location ~ /\.ht {
            deny  all;
    }
}

(each index.php has its own set local var within it like so for fr):
// Path to your craft/ folder
$craftPath = '../../craft';

// Tell Craft to serve the local site
define('CRAFT_LOCALE', 'fr');

// Do not edit below this line

My General config is
 array(
        'en' => 'http://www.site.com/',
        'ar' => 'http://www.site.com/ar/',
        'es' => 'http://www.site.com/es/',
        'fr' => 'http://www.site.com/fr/',
        'hu' => 'http://www.site.com/hu/',
        'it' => 'http://www.site.com/it/',
        'ru' => 'http://www.site.com/ru/',
        'zh' => 'http://www.site.com/zh/',
    ),
    'maxUploadFileSize' => 2147483647,

    );

This results in the server displaying the correct links to my localised articles in the menu and the en language serves up entries correctly, however other languages are found at /local/local/entitypath not local/entitypath.
Adding site_urls to my config seems to break things more, causing locals to not be served up at all.

**Tags:** localization
> **Comments:**
> **username_1**: As per http://buildwithcraft.com/help/localization, what do you have in /craft/config/general.php and /ru/index.php, /zh/index.php etc files?  
> **username_0**: Sorry, updated with more information, thanks.  
> **username_2**: Hi @user2556299! Would you mind accepting the answer that ended up being the most helpful? If there hasn't been an answer that solved your problem, it might help to update your question.  

---

## 2 answers

### Answer by username_3 on 2014-07-10. Score: 4 | Accepted answer

When you are following the each-locale-gets-its-own-index.php-file pattern as outlined in the official KB article, “How do I show localized content on the front end?”, then you do not need to include the locale ID in your sections’ Entry URL Format settings.
For example if you have a News section, and you want Arabic entries to get URLs that look like:
http://www.site.com/ar/news/my-entry-slug

Then the Arabic Entry URL Format should just be this:
news/{slug}

not this:
ar/news/{slug}

Everything leading up to “news/{slug}”, including “ar/”, is handled by your Arabic site URL, as defined in your config/general.php file’s siteUrl setting:
'siteUrl' => array(
    'en' => 'http://www.site.com/',
    'ar' => 'http://www.site.com/ar/',
    // ...
),

> **Comments:**
> **username_1**: I think we posted an answer at the same time...  
> **username_0**: Thanks Brandon, I thought as much but couldn't see it documented anywhere.  Is there any advantage to using one approach over another? I know that some elements of the site (such as my news feed) won't be translated so is craft able to fall back to a master local if there isn't a version in the users preferred local available?  I was also hoping to take a guess at the users local from their ip address and redirect them to the site for their language.  
> **username_3**: @AndreaDeMers SE says I beat you by 16 minutes :)  
> **username_3**: @user2556299 Which approaches are you referring to? The way outlined above is what pretty much everyone has done to date, that I know of.  As for your other question – probably best to ask that as a separate question as the answer will be pretty involved.  
> **username_0**: I was refering to specifying the url in each section per local in craft over using the php method and specifying the local via PHP - obviously the php way seems less effort but I don't really understand why it is in the CMS if everyone just uses the the PHP override.  
> **username_3**: The Entry URL Format setting is locale-specific in case the path should actually be translated depending on the locale. I.e. if you have a News section, you might want that to be `news/{slug}` for the English site, and `noticias/{slug}` for the Spanish site.  

---

### Answer by username_1 on 2014-07-10. Score: 3

When you write:

> I've had the most luck with this nginx config, together with specifying the local in the section urls in the cms for each section.

Are you referring to:

![enter image description here](https://i.sstatic.net/w4ill.png)

?

If so, and you put the locale, in this case: `fr_ca/a-apropos`, try removing `fr_ca`.


---

