Is there a way using htaccess to add a virtual directory in URI?

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

Related posts

2 comments

  1. This should work for you:

    RewriteEngine on
    RewriteRule ^[a-z]{2}/(.*)$ /$1 [QSA,L]
    

    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:

    RewriteEngine on
    RewriteRule ^(es|fr|us)/(.*)$ /$2 [QSA,L]
    

    Making sure you add the ones you want between the first set of parantheses (and separated by pipes (|) as shown above.

Comments are closed.