Skip to content

Instantly share code, notes, and snippets.

@hugodias
Created June 28, 2020 23:29
Show Gist options
  • Save hugodias/83b83d0092e6586dc041f8256f41f691 to your computer and use it in GitHub Desktop.
Save hugodias/83b83d0092e6586dc041f8256f41f691 to your computer and use it in GitHub Desktop.
Multi Language WordPress htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(br|en|es)$ index.php?lang=$0 [L,QSA]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
<?php
function is_multilanguage_front_page()
{
return ! empty($_GET) && ! empty($_GET['lang']) && in_array($_GET['lang'], array(
"en",
"es",
"br"
));
}
function language_redirect($template)
{
if (is_multilanguage_front_page()) {
return locate_template(array('front.php'));
} else {
return $template;
}
}
add_action('template_include', 'language_redirect');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment