Skip to content

Instantly share code, notes, and snippets.

@maaaks
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maaaks/8818231 to your computer and use it in GitHub Desktop.
Save maaaks/8818231 to your computer and use it in GitHub Desktop.
A simple (?) multilanguage site configuration for
# When opened on *.ru domain, show /content/ru/pagename.php
# When opened on other domain, show /content/en/pagename.php
Options -Indexes +FollowSymlinks
RewriteEngine On
RewriteBase /
# Prevent from multiple runs of this file
RewriteCond %{ENV:REDIRECT_WASHERE} !^$
RewriteRule ^ - [L]
RewriteCond %{ENV:WASHERE} !^$
RewriteRule ^ - [L]
RewriteRule ^ - [E=WASHERE:YES]
# Remove www prefix
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L,R=301]
#######
# Here is the place for special magic
RewriteRule ^index/?$ / [L,R=301]
#######
# When accessing static files, return them directly
RewriteRule ^s/(.+)$ s/$1 [L]
# All other URLs should have trailing slashes
RewriteRule ^(.*[^/])$ $1/ [L,R=301]
# Choose language depending on domain
RewriteCond %{HTTP_HOST} \.ru$
RewriteRule ^ - [E=LANGUAGE:ru]
RewriteCond %{ENV:LANGUAGE} ^$
RewriteRule ^ - [E=LANGUAGE:en]
# Empty means «index.php», trailing slash means «.php»
RewriteRule ^$ index.php
RewriteRule ^(.*)/$ $1.php
# Convert page name to file name
RewriteRule ^(.*[^/])/?$ content/%{ENV:LANGUAGE}/$1 [L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment