we have a multilingual website and everything is based on the language segment in the uri. eg.
- /en/home
- /fr/home
- /nl/home
Now I want my 404 page for a uri without a language segment to redirect to one with a language segment, preferably based on the browser language. That way my 404 page will hava a language attached.
eg. http://www.website.be/test should redirect to http://www.website.be/en/test (when EN is the browserlanguage)
At the moment this is my .htaccess file
# Add www - only for production urls
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^website\.localhost [NC]
RewriteCond %{HTTP_HOST} !^192\..+$ [NC]
RewriteCond %{HTTP_HOST} !^dev\..+$ [NC]
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# REMOVE TRAILING SLASH
# Make sure it's not a directory root
RewriteCond %{REQUEST_FILENAME} !-d
# Catch any+all characters and throw a slash in as the last character
RewriteCond %{REQUEST_URI} ^(.+)/$
# Redirect to same URI sans trailing slash (and use 301 for SEO goodness)
RewriteRule ^(.+)/$ /$1 [R=301,L]
# Removes index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]
# Redirect based on browser accept language FR
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteCond %{QUERY_STRING} !^(ACT=.*)
RewriteCond %{QUERY_STRING} !^(MOBILE_ACT=.*)
RewriteRule ^$ /fr [L,R=301]
# Redirect based on browser accept language EN
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteCond %{QUERY_STRING} !^(ACT=.*)
RewriteCond %{QUERY_STRING} !^(MOBILE_ACT=.*)
RewriteRule ^$ /en [L,R=301]
#NO LANGUAGE FOUND - NL = DEFAULT
RewriteCond %{QUERY_STRING} !^(ACT=.*)
RewriteCond %{QUERY_STRING} !^(MOBILE_ACT=.*)
RewriteRule ^$ /nl [L,R=301]