I am trying to redirect all requests for my default language (nl) to /nl..... (without showing the redirect to the user). So example.com should redirect to example.com/nl without visibly altering the url in the browser. Here is what I tried:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/en.*
RewriteCond %{REQUEST_URI} !^/nl.*
RewriteRule ^(.*)$ nl$1 [R,L]
The redirect is visible to the user (/nl/index.php) and in addition it results in a 'too many redirect'.
If I try [P,L] I get: no permission to access '\' on this server.
What is the correct way to achieve what I want?
There's shouldn't be an
[R]
after the RewriteRule as this tells Apache to send a 302 redirect rather than internally rewriting the URL.The second part of the RewriteRule should start with a slash unless this is in a Directory context (such as in a
.htaccess
file or a<Directory >
block). Without the slash, you are rewriting the URL to something likehttp://example.comnl/index.php
rather thanhttp://example.com/nl/index.php
.