1

I have a very basic PHP website that is currently setup for two languages like so:

  • lang.en.php - English strings

  • lang.es.php - Espanol strings

  • en/ - folder with PHP pages (PHP first processes the URL and loads the appropriate strings - in this case, lang.en.php); files are EXACTLY the same as en/

  • es/ - folder with PHP pages (PHP first processes the URL and loads the appropriate strings - in this case, lang.es.php); files are EXACTLY the same as es/

  • index.php - redirects the user to the appropriate sub-directory based on the user's browser language

This seems to work fine for both SEO and easy management, except for the file duplication in the en/ and es/ folders. If I ever want to update/add a page, I have to upload the same file to both en/ and es/. Is there a way to have the en/ and es/ folders pull the same files from say, a common/ folder? I would like to keep the en/ and es/ directories because it's user friendly and, from my understanding, good for SEO.

Any help would be much appreciated!

EDIT: I've considered using a GET variable for the language (ie. ?lang=en) which would solve my issue of duplication and allow me to replace the directories en/ and es/ with a common directory for all languages in which each page's language is determined by the lang variable. However, would this be bad for SEO?

1 Answer 1

0

Instead to redirect in the index.php file to the appropiate folder, do this:

  1. Load appropiate language file based on the user's browser language (a simple "require").
  2. Instead of redirect the user to the folder, load ("require") from the 'common' folder the file that user asked for.
2
  • I like that approach, but wouldn't there be a problem with SEO? Unless I'm misunderstanding this, wouldn't the URLs be the same for both languages?
    – Stone
    Commented Jun 13, 2012 at 23:18
  • Yes, if you need to preserve the language structure, you can use the HTTP:Accept-Language in .htaccess to redirect from es/ en/ folders to common/ transparently
    – Ivan
    Commented Jun 14, 2012 at 7:39

Your Answer

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

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