Home›Support›English Support›[Resolved] Site URL - how to automatically direct to en or fr based on user locale detection?
[Resolved] Site URL - how to automatically direct to en or fr based on user locale detection?
This thread is resolved. Here is a description of the problem and solution.
Problem: The client's site loads 'broken' when accessed without specifying 'EN' or 'FR' in the URL. This issue occurs when the WPML plugins are active. Solution: We recommend checking if you are using the 'Use directory for default language' option in WPML, which requires setting up a Root Page. For more information on what a Root Page is and whether you need one, please visit What is a Root Page, and do I need one? Additionally, consider setting up a redirection from the root domain to the default language directory. Detailed guidance on this can be found here: Redirect the root domain to the default language directory
If this solution does not apply to your case, or if it seems outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If issues persist, please open a new support ticket.
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.
Background of the issue:
We're working on a site that's behind our firewall and not live yet: hidden link. It's a single site version of a current multisite production site. We'd like the site to default to hidden link when a user in the US accesses it. Entering that manually works fine. However, when hitting the URL without EN or FR, the site loads 'broken'. The language switcher works and the French version of the site works as well: hidden link. When we turn off our WPML plugins, the URL hidden link works without issue.
Symptoms:
The site loads 'broken' when accessed without specifying EN or FR in the URL.
Questions:
Do we need to adjust a setting in WPML or change something in htaccess or wp-config?
Yes, we still need assistance please. We confirmed that we are using a root page and that the root page seems to exist and it's the same setup and root page as the original site, so that was transfered over correctly.
Again, these work: hidden link hidden link
The question is why this: hidden link
Doesn't automatically redirect to: hidden link (if the user has EN locale set)
or hidden link (if the user has FR locale set)
We'd like it to default to EN if no locale is set or if the locale doesn't match EN or FR.
We do have root-rediect.php template and I tried to update the root page to use it, however, it won't let me save it, strangely. I can probably update it on the database side though (?)
Please confirm what these should be:
WordPress Address (URL) Currently --> hidden link
Site Address (URL) Currently --> hidden link
I know the redirect page uses home_url(), which (if either) of those addresses does it use? If my research is correct, it uses the "Site Address" ?
Quick update we were successful editing the root page to the root redirect template. The base url is now /en so it seems like everything is working as expected.
We are seeing another weird issue of an .htaccess file being created after making a change in Settings --> General that was causing the site to crash (500 error) we found and deleted the file and everything worked again. Not sure what that story is with that. The htaccess file was being created in the root or where it didn't seem to belong. Any ideas?
Thanks.
New threads created by Andrey and linked to this one are listed below:
I'm glad to hear that it now works. As the original issue is resolved, I opened a new ticket to answer your new question. This will also help other users with similar problems find solutions when searching the forum.