Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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.
share|improve this answer
    
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 Jun 13 '12 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 Jun 14 '12 at 7:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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