Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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 like http://example.comnl/index.php rather than http://example.com/nl/index.php.

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/en.*
RewriteCond %{REQUEST_URI} !^/nl.*
RewriteRule ^(.*)$  /nl$1 [L]
share|improve this answer
    
I then get: Internal Server Error and in my log: Request exceeded the limit of 10 internal redirects due to probable configuration error. r->uri = /index.php redirected from r->uri = /index.php redirected from r->uri = /index.php ... redirected from r->uri = / –  zensys Jan 17 '13 at 12:33
    
Is this the only rewrite rule you have in your configuration? The above rules and even your original rules are not able to cause that redirect to happen. –  Ladadadada Jan 17 '13 at 13:03
    
there was another rule which caused the trouble, it works now, thanks! –  zensys Jan 17 '13 at 15:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.