0

I'm trying to add languages to my wordpress website. For this I'm using "qTranslate X" plugin in "per domain" mode.

It should work as follows:

http://domain.com - main language
http://en.domain.com - english
etc...

What I need is to redirect all requests from subdomain to main domain. The rest will be done by the plugin.

Example:
http://en.domain.com/category/article
should be redirected to
http://domain.com/category/article

I modified main .htaccess WP file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^en\.domain\.com [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

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

But, unfortunately, it works only for the home page (i.e. http://en.domain.com). When I type http://en.domain.com/category/article I see 404 Not Found page.

Thanks for any help!

Arsen K.
  • 5,494
  • 7
  • 38
  • 51

2 Answers2

1

You need to perform a URL rewrite, not a redirect which you are specifying with R=301 to generate an HTTP redirect with the status code 301.

Presumably you have a wildcard DNS entry such that *.domain.com goes to your web server, and WordPress is installed at domain.com. The following code should rewrite your URL to access the proper page and language. Note that the RewriteCond was modified to specify multiple languages with (en|es|fr) and that the RewriteRule only specifies the L option indicating it is the Last rule to be processed.

RewriteBase /
RewriteCond %{HTTP_HOST} ^(en|es|fr)\.domain\.com [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L]
doublesharp
  • 26,888
  • 6
  • 52
  • 73
0

I've spent a lot of hours googling and, finally, found an answer. I want to remind, that my problem was to adjust "qTranslate X" plugin to serve my multilingual website. So here's what I did to achieve this.

In Settings -> Permalinks I have "custom structure" checked, http://domain.com/%category%/%postname%

In qTranslate -> "Advanced Settings" -> URL Modification Mode: Use Per-Domain mode. I set "domain.com" for main language, "en.domain.com" - english etc.

You don't have to change default WordPress .htaccess code for permalinks custom structure, it perfectly works with "qTranslate X" plugin. So make sure your .htaccess file looks like this.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

The only thing, that needs to be done, is to make sure, that requests to subdomain are processed as requests to the main domain. I.e. your subdomain folders must point to the folder, where WordPress is installed. On different hostings it may be achieved by different ways. As for me, in the domain settings I've found an option "process all requests from subdomains, that don't exist". So I didn't even have to create any subdomains at all! Just a single chechbox. If you are not sure, how to do this, contact your hosting support service and ask them to help.

Arsen K.
  • 5,494
  • 7
  • 38
  • 51
  • 1
    Glad you got it working, this is effectively what the htaccess does in my answer, rewrites the subdomain to the main Wordpress install. – doublesharp Jul 26 '15 at 14:48