Using .htaccess with dynamic folders – wordpress

I have this .htaccess file in the root of my wordpress site.

RewriteEngine on

#For the spanish language, redirect to the spanish translation
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteRule ^$ %{REQUEST_URI}es/ [L,R=301]

#For every other language (including English) use English(the default)
RewriteRule ^$ %{REQUEST_URI}/ [L,R=301] #can remove this i know 

This is working fine for the root of the site. e.g www.mysite.com, if the user’s browser language has spanish default, it will redirect to www.mysite.com/es/

Read More

However, if the user clicks another link to www.mysite.com/help/, it does not load the help page in spanish – expected it to load automatically, www.mysite.com/help/es/

Note:

  1. I cannot put .htaccess in all sub folders – they are dynamically generated. (or i don’t know how to)
  2. I have tried putting these settings in /etc/apache2/apache2.conf in the . It still does not help.
  3. I need to avoid infinite loops

How do i make this happen?

This is the complete mod_rewrite part, after the first answer

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteRule ^assets/css/(.*) /wp-content/themes/mytheme/assets/css/$1 [QSA,L]
RewriteRule ^assets/js/(.*) /wp-content/themes/mytheme/assets/js/$1 [QSA,L]
RewriteRule ^assets/img/(.*) /wp-content/themes/mytheme/assets/img/$1 [QSA,L]
RewriteRule ^plugins/(.*) /wp-content/plugins/$1 [QSA,L]

#For the spanish language, redirect to the spanish translation
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteCond %{REQUEST_URI} !es [NC]
RewriteRule .? /es%{REQUEST_URI} [L,R=301]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Related posts

Leave a Reply

1 comment

  1. Try this one:

    RewriteEngine on
    
    
    #For the spanish language, redirect to the spanish translation
    RewriteCond %{HTTP:Accept-Language} ^es [NC]
    RewriteCond %{REQUEST_URI} !es [NC]
    RewriteRule .? %{REQUEST_URI}es/ [L,R=301]