Answered & edited !

I have a single Wordpress installation on example.com.

I use Polylang plugin to add multilingual system to this website. I have 16 languages, and it's configured to use example.com/fr for French, example.com/de for German, etc ...

I want to use domain name for Korean language and Japan. Instead of example.com/jp, I want to get the website on example.jp.

I'm trying to find a way to do this with .htaccess without moving the others languages on sub domains or domains.

Here is what I have, but if I go to example.jp/page/ I'm redirected to example.com/ja/page/, do you know a way to hide this redirection ?

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?example\.jp$
RewriteRule (.*) http://example.com/ja/$1 [R=302,L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Another information if you need, the domain are using CNAME, and I'm on a WP Engine hosting. Concerning permalinks, I'll be able to pass them into a filter to clear the current subdirectory links system.

Thanks for your time !

EDIT : As explained in the answer, the CNAME and server file system gives me everything I need. I don't need to use .htaccess to achieve what I'm looking for.

1 Answer 1


Providing you've already updated the internal links and that example.jp points to the same place on the filesystem as example.com (via CNAME and appropriate server config changes) then you don't necessarily need to rewrite to example.com, since example.jp accesses the same files. Trying to rewrite to a different domain will implicitly trigger an external redirect anyway (regardless of whether you specify the R flag on the RewriteRule directive).

So, to change this to a rewrite on the example.jp domain:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.jp
RewriteRule (.*) /ja/$1 [L]

(Why are you using ja in the substitution string - is that a typo? Shouldn't it be jp as mentioned earlier in your question?)

However, this may trigger a rewrite-loop, depending on whether you have other directives. So, you would probably need to add a condition to prevent this. For example:

RewriteCond %{REQUEST_URI} !^/ja/
RewriteCond %{HTTP_HOST} ^(www\.)?example\.jp
RewriteRule (.*) /ja/$1 [L]

The additional RewriteCond directive ensures that the requested URL does not (! prefix) already start with /ja/.

Although it would be more efficient to avoid rewriting /ja/ URLs with a check in the RewriteRule pattern instead. For example:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.jp
RewriteRule !^ja/ /ja%{REQUEST_URI} [L]

Now, the RewriteRule is only processed when the URL does not start /ja/, instead of processed every request (ie. .*).

However, WordPress may still try to canonicalise the hostname? ie. WordPress itself might issue an external redirect to example.com. If this is the case then you will need to override this in WordPress or implement a reverse proxy using mod_proxy - for which you will ideally have access to the server config.

  • 1
    Many Thanks for your help. I haven't realize that CNAME already gives me the redirection, I'll probably have to find a way to do it in PHP then. Because you're right : example.jp/ja/mypage gives me the right page. You find the answer without the question ! ("ja" is the language slug)
    – Elex
    Jun 10, 2018 at 15:29

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.