Vallieres
Vallieres

Reputation: 879

Redirect Wordpress Sub Folder to a Sub Domain

I have a site that is actually a multisite using subdomains and I would like to remap the subfolder translations to a sub domain.

domain.com (main site)
blog.domain.com (mu site for the blog)

With WPML, I have:

domain.com/fr/ (for the French translation)
blog.domain.com/fr/ (for the French translation)

I would like to have the following:

domain.com/fr/ --> fr.domain.com
blog.domain.com/fr/ --> blogue.domain.com

I think this could be possible with Rewrite rules, but I can't get it to work properly.

Here is the current default Wordpress MU .htaccess:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

Many thanks for your help!

Upvotes: 1

Views: 200

Answers (2)

anubhava
anubhava

Reputation: 785146

Keep your .htaccess like this:

RewriteEngine On
RewriteBase /

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

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

RewriteRule ^index\.php$ - [L]

RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^(wp-(content|admin|includes).*) $1 [L]

RewriteRule ^(.+?\.php)$ $1 [L]

RewriteRule . index.php [L]

Upvotes: 1

arco444
arco444

Reputation: 22831

You can add to .htaccess:

RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^/fr/ http://fr.domain.com/fr/ [R,L]

RewriteCond %{HTTP_HOST} ^blog\.domain\.com
RewriteRule ^/fr/ http://blogue.domain.com/fr/ [R,L]

Upvotes: 0

Related Questions