I noticed that there are already very similar questions to mine, that have been answered already on this site. But I have been struggling a lot without succeeding in implementing the solution provided there, so I dare to pose this question again. Could you please help?
I have developed a web site in wordpress, and I have put everything under a specific subdirectory (my host provider uses Apache, needless to say), so that:
- All files are in /public_html/es/ (the name of the subdirectory is "es" for some historical reasons, I just specify it here because it is a very common string that may require very accurate regex).
- Everything works fine and I can navigate to the site at the URL www.example.com/es and then follow the links to, for example www.example.com/es/whatever1/whatever2/
- Moreover, I have implemented a multilanguage plugin that allows pages to be displayed as www.example.com/es/whatever1/whatever2/?lang=it when I want to switch to another language (Italian in this example).
- Finally I have coded the .htaccess files as follow, to allow visitor to access the page just typing the domain name:
/public_html/.htaccess:
#
# /public_html/.htaccess
#
# HISTORY
# 20160309 pdoc (B) ADDED CODE TO ALLOW LOADING OF FONT-AWESONE ICONS ALSO
#
# 20160309 pdoc (B) added next 3 lines
<FilesMatch ".(eot|ttf|otf|woff)">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^http://example.com$ [OR]
RewriteCond %{HTTP_HOST} ^https://example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$ [OR]
RewriteCond %{HTTP_HOST} ^http://www.example.com$
RewriteRule ^/?$ "https\:\/\/www\.example\.com\/es" [R=301,L]
/public_html/es/.htaccess:
#
# /publi_html/es/.htaccess
# CHANGES:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /es/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /es/index.php [L]
</IfModule>
# END WordPress
Technically speaking, it seems to work fine: you can access the site by typing "example.com" and then navigate through it because the URL is converted to "example.com/es".
Now... the "/es/" string that appears in the browser URL field is annoying, and sometimes misleading, because it makes some visitor believe they are in the"spanish" version of the site, while that string is just a piece of the path.
I do not want to move the whole site to another path under /public_html, is there a way I can hide the "/es" string from the browser URL field? Of course, I need to hide only the 1st occurrence of "/es" (i.e. I want that
example.com/es/thesubdirectory/?lang=xx
is shown as
example.com/thesubdirectory/?lang=xx
).
As commented initially, I could not implement successfully any advice I found elsewhere in stackoverflow.
Thanks a lot for your patience reading this long post.