I have my wordpress installed on www.site.com/blog/ but i would like to add language codes in front of the blog directory (www.site.com/us/blog/, www.site.com/es/blog/ and so on). Is there a way achiving this? I need to keep those virtual directories inside URI so when visiting www.site.com/us/blog i want to show www.site.com/us/blog in the address bar.
This is my .htaccess file from www.site.com/blog/ directory.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress
it’s been a while since i’ve written .htaccess, let me know how this works out.
edit: here’s a helpful tutorial on how it works 🙂
https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
This should work for you:
It checks for any 2 letter prefix at the start of the URL, followed by anything else, then treats that as a request for the bit after, so
/us/blog
will be treated as a request for/blog
, just as/es/page/123
would be treated as a request for/page/123
. So long as a visitor goes to the prefixed URL, the address won’t be redirected.If you want to be more specific about what language prefixes to use, do this instead:
Making sure you add the ones you want between the first set of parantheses (and separated by pipes (
|
) as shown above.