For a multi-langue site I have used the following code to automatically redirect people to the right page. This works great, but does not include stylesheets and other files.
The following code in .htaccess turns http://www.site.com to http://www.site.com/fr if a visitor is from France. But it also redirects stylesheet and other files.
RewriteCond %{HTTP:Accept-Language} ^(nl.*) [NC]
RewriteCond %{REQUEST_URI} !(^/nl/.*) [NC]
RewriteRule ^(.*)$ /nl/$1 [L,R=301]
RewriteCond %{HTTP:Accept-Language} ^(fr.*) [NC]
RewriteCond %{REQUEST_URI} !(^/fr/.*) [NC]
RewriteRule ^(.*)$ /fr/$1 [L,R=301]
RewriteCond %{REQUEST_URI} !(^/.*) [NC]
RewriteRule ^(.*)$ /$1 [L,R=301]
http://www.site.com/css/style.css turns into http://www.site.com/fr/css/style.css which doesn’t exist
http://www.site.com/js/file.js turns into http://www.site.com/fr/js/file.js which doesn’t exist
Is there a way to create an auto redirect, but exclude whole subdirectories? For example, exclude /css/. and /js/.
You can use
so that requests to files and directories that exist will not be rewritten