6

I'm developing and running a Craft site locally through Laravel Homestead and am having issues with pages 404'ing in a multi-locale setup.

I've followed this guide closely: https://craftcms.com/docs/localization-guide and still running into problems.

Basically, I want to have a Spanish locale set up, with English as the default top level. So my example.com/xyz-article will be the English version, and example.com/es/xyz-article will be the Spanish version.

Here is how my folder structure is set up:

craft/
public/
   .htaccess
   index.php
   es/
      index.php
      .htaccess

My craft/config/general.php is set up like this:

return array(
    '*' => array(
        'omitScriptNameInUrls' => true,
    ),

    '.dev' => array(
        'devMode' => true,
        'userSessionDuration'           => 'P101Y',
        'rememberedUserSessionDuration' => 'P101Y',
        'rememberUsernameDuration'      => 'P101Y',
        'invalidLoginWindowDuration'    => 'P101Y',
        'cooldownDuration'              => 'PT1S',
        'maxInvalidLogins'              => 101,
        'siteUrl' => array(
            'en_us' => 'http://example.dev/',
            'es' => 'http://example.dev/es/',
        )
    ),
);

My index.php file under the public/es directory looks like this:

<?php

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

// Tell Craft to serve the Spanish content
define('CRAFT_LOCALE', 'es');

// Do not edit below this line
$path = rtrim($craftPath, '/').'/app/index.php';

if (!is_file($path))
{
    if (function_exists('http_response_code'))
    {
        http_response_code(503);
    }

    exit('Could not find your craft/ folder. Please ensure that <strong> <code>$craftPath</code></strong> is set correctly in '.__FILE__);
}

require_once $path;

Finally, both of my .htaccess files inside the public and es directories are identical and look like this:

<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>

Going to example.dev brings up the English homepage just fine, and example.dev/es brings up the Spanish homepage just fine. Everything looks good so far...but when I try to navigate into subdirectories, the es/ pages always 404's.

For instance, I set up a Single called "Testing", enabled it for both locales, and pointed it to a template inside my craft/templates folder called testing/index.html. example.dev/testing brings up the English version, but example.dev/es/testing gives me a 404 error.

The odd thing is, is that the ugly version of the URL at http://example.dev/index.php/es?p=testing brings up the Spanish version, and Live Preview also works and displays/updates when I'm working on the Spanish version of the page.

I'm at a bit of a loss as to where I'm going wrong here -- it seems like some paths are just screwy but I can't find where I may have entered something in incorrectly. Any help would be appreciated!

UPDATE: Here are the log errors I'm getting when I load the es/testing page.

enter image description here

3
  • Did you ever get this resolved? (I am having the identical problem) May 30, 2016 at 18:44
  • Same problem here... No idea how to fix it.
    – jlcharette
    Aug 25, 2016 at 13:08
  • @Tyler I'm having the exact same issue as this in Craft3 RC2. Did you ever find a solution? Dec 19, 2017 at 16:07

3 Answers 3

2

I was running into the same issue, struggling with it and it turns out that the official documentation is a bit misleading (no offense) when it comes to the .htaccess file, because it just mentions to copy it:

You can not just copy the .htaccess but you have to change the RewriteBase parameter according to your folder structure in the /public folder.

In your case the .htaccess file in the /public folder should start like this:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    (...)

Within your /public/es folder you should have the following in the .htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /es/

    (...)

Hope that helps!

TL;DR —> The RewriteBase in the .htaccess has to be changed according to the folder setup of the locales

1
  • Thank you very much for finding the solution! You saved my project. It is still very odd to me that this is an issue as I've never had this issue on any of my other sites with CraftCMS, so I'm wondering if this is only an issue on my staging server because I used a subdomain for the staging? Thanks again! Mar 9, 2021 at 17:06
1

Turn devMode on, trigger the 404, and look at the craft.log -- it should give you the URL that's causing the 404 error, which should help in debugging it.

5
  • Any idea of what kinds of errors I should be looking for specifically in craft.log? I have something like this in there: WHERE (elements_i18n.uri = :uri) AND (elements_i18n.locale = :locale) AND (elements_i18n.enabled = 1) AND (elements.enabled = 1) AND (elements.archived = 0). Bound with :uri='es/testing', :locale='en_us') -- no idea if something like that is helpful.
    – Tyler
    Sep 21, 2015 at 17:36
  • You should see something like this: 2015/09/21 17:42:59 [error] [exception.Craft\HttpException.404] exception 'Craft\HttpException' in /var/www/oluminisites/craft/app/controllers/TemplatesController.php:59 REQUEST_URI=/wp-includes/images/lndex.php?php4&root&upl&wphp4&abdullkarem&450799&wp& Sep 21, 2015 at 18:20
  • Ah, gotcha. Yup, I'm seeing a lot of this: 2015/09/21 16:37:00 [error] [exception.Craft\HttpException.404] exception 'Craft\HttpException' in /home/vagrant/cms/craft/app/controllers/TemplatesController.php:59
    – Tyler
    Sep 21, 2015 at 19:18
  • There's a stack trace after that, but the end REQUEST_URI statement looks like this REQUEST_URI=/es/testing
    – Tyler
    Sep 21, 2015 at 19:49
  • @Tyler - any solution for this yet?
    – VoA
    May 31, 2017 at 1:41
1

Have you checked if your .htaccess file inside the /es directory gets interpreted? Write some crap in it and check if you get an error 500. If it does not, make sure you have AllowOverride set to All in your apache config.

And also check if you're really using apache, otherwise you need to configure your Nginx, ... in a different way for the subdir. see here: https://github.com/nystudio107/nginx-craft

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.