Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
With domain per langauge, The secondary domain with www. version always redirects to primary domain instead of displaying the translation

Solution:
Client htaccess rule which works best

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]

100% of people find this useful.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 6 replies, has 2 voices.

Last updated by Ilana Wilner 4 years, 5 months ago.

Assisted by: Raja Mohammed.

Author Posts
June 3, 2020 at 11:35 pm #6287811

Ilana Wilner

Hi,

I am having the exact same issue as is explained here:

https://wpml.org/forums/topic/second-language-www-domain-working-non-www-defaults-to-english/

So the "www.abcalphapourlavie.ca" goes to the French version of the site, however with just "abcalphapourlavie.ca" (no www) it goes to the English URL, which is hidden link

We tried the solutions in the above support ticket but they didn't seem to work for us.

Here is the WordPress section of our .htaccess file:

# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<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

Any ideas?

Thanks!

June 4, 2020 at 7:19 pm #6298287

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello there,

Try adding the below code to the top of .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^/(.*)$ <em><u>hidden link</u></em> [R=301,L]
</IfModule>

Let me know if that helps.

Kind regards
Raja

June 4, 2020 at 9:45 pm #6299067

Ilana Wilner

Hi Raja,

Thanks for your help!

When I pasted what you gave me into the .htaccess file, there was no effect at all. We've tried putting it at the top of .htaccess, inside of # BEGIN WordPress, and after # END WordPress.

Please note that we have changed the primary URL in WPML to not have the 'www'.

So WPML is now configured as follows:

A different domain per language
EN hidden link
FR hidden link

Of course the issue now is that with the "www" the URL does not work.

hidden link (works)

hidden link (does not work).

We need it to work with the both the 'www' and without the 'www' for both the home page and all inside pages.

Or for something to strip out the 'www' universally.

We'd appreciate any help you can provide!

Thanks

June 5, 2020 at 4:08 pm #6307283

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

May be you can try with more specific rule to target the domain name, Use this htaccess rule instead of the previous one.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.abcalphapourlavie.ca [NC]
RewriteRule ^/(.*)$ <em><u>hidden link</u></em> [L,R=301]

If your server has a caching mechanism enabled by default please flush and remove the cache before you can give it a try.

June 5, 2020 at 6:39 pm #6307983

Ilana Wilner

Hi Raja,

Thanks for your help but this didn't work either... However, we found a solution that did work! I am sharing it here in case it helps others:

#Rewrite rule for WPML to strip www from URL if exist
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ hidden link{REQUEST_URI} [R=301,QSA,NC,L]

This has the effect of stripping out the "www." from any URL, ensuring https:// and most importantly it works with inside pages too.

June 5, 2020 at 6:45 pm #6308063

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Glad that you manged to resolved the issue with a working solution. Thanks for sharing the same i will add this to the ticket summary so that others can benefit from it as well.

I hope we can mark the ticket as resolved?
Feel free to contact us if you need further assistance with our plugin.

Have a great day.