3

So I've setup locales following the official guide and am going with the option where English (en_gb) is the default and Danish (da_dk) is in a sub-folder:

http://mysite.com --> en default
http://mysite.com/dk/ --> dk sub-folder

In summary, I've set the locales in Settings -> Locales

enter image description here

I've enabled them for my section (which is a channel):

enter image description here

I've set the siteURL array (single domain config):

'siteUrl' => array(
    'en' => 'http://mysite.com',
    'dk' => 'http://mysite.com/dk/',
),

I've created the folder structure and copied the index.php file and .htaccess file across to the dk/ folder:

craft/
public_html/            --> mysite.com/
    .htaccess
    index.php
    dk/                 --> mysite.com/dk/
        .htaccess
        index.php

And I've made the edit to the dk/index.php file:

// Path to your craft/ folder
$craftPath = '../../craft';

// Tell Craft to serve the Danish content
define('CRAFT_LOCALE', 'dk');

Viewing my entry in English works fine:

http://mysite.com/segment/title  --> Shows in English

Viewing the same entry in Danish directs to:

http://mysite.com/danishsegment/title --> Missing /dk/ in URL. Nothing shown

So the preview link for Denmark doesn't include the country segment in the URL (dk/) and results in a 404. Even manually adding dk/ to the URL results in a 404. It doesn't seem to be recognising the Danish locale at all.

Any ideas as to what I'm doing wrong?

UPDATE:

Here are the contents of my .htaccess files. All standard Craft with a Type to ensure PHP 5.6 is used:

AddType x-httpd-php56 .php

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Send would-be 404 requests to Craft
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
    RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>

UPDATE 2:

The 'Offers' section (Channel) is set to have a different URL for each Locale:

enter image description here

  • 1
    Is there a RewriteBase in the .htaccess in the Danish locale directory? – megatrond Jul 23 '15 at 17:02
  • No RewriteBase in any .htaccess file. I looked for that originally in case that was causing the problem. I've updated my question with the contents of my .htaccess file for reference. – Ian Jul 23 '15 at 17:51
  • What is AllowOverride set to? – megatrond Jul 23 '15 at 18:05
  • In php.ini? I don't have access to the php.ini file directly but it is set to true. I have lots of other sites setup and working with custom .htaccess files. Even with Craft it's all been working fine. It's just now I'm adding in locales that for some reason it doesn't seem to want to add the /dk/ segment to the URL - even when clicking on the link in the Entries panel of Craft. It doesn't include the /dk/ part in the URL and adding it results in a 404. http://mysite.com/dk/ shows the index page but the custom Section URL for Denmark is added or apparently working. – Ian Jul 23 '15 at 18:12
  • Granted I have all the config in /etc/httpd/vhosts/hostname.conf, but I do have the locale prepended in the rewrite for the one multilocale site I have running: RewriteRule (.+) /en/index.php?p=$1 [QSA,L] – megatrond Jul 23 '15 at 19:03
2

Have you tried putting da_dk in as the key in the siteUrl array?

  • Closer! That solves half of the problem. The links in the Entries listing now correctly link to mysite.com/dk/tilbud-og-kampagner/{title}. The trouble is that it still results in a 404. mysite.com/dk/ correctly shows the index page. It seems like it's so close. – Ian Jul 23 '15 at 19:35
  • And you obviously removed the dk part in the rewriterule? – megatrond Jul 23 '15 at 19:36
  • Yep, that's back to RewriteRule (.+) index.php?p=$1 [QSA,L]. – Ian Jul 23 '15 at 19:39
  • Oddly the live preview for the Danish version of the entry works fine. It's just the actual page URL itself which doesn't resolve. – Ian Jul 23 '15 at 19:42
  • Maybe you need to do define('CRAFT_LOCALE', 'da_dk'); as well? – megatrond Jul 23 '15 at 19:46

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.