我试图redirect我的默认语言(nl)的所有请求到/ nl …..(不显示redirect到用户)。 因此,example.com应该redirect到example.com/nl,而不会明显地改变浏览器中的url。 这是我试过的:
RewriteEngine On RewriteCond %{REQUEST_URI} !^/en.* RewriteCond %{REQUEST_URI} !^/nl.* RewriteRule ^(.*)$ nl$1 [R,L]
用户可以看到redirect(/nl/index.php),并且导致“redirect太多”。
如果我尝试[P,L],我得到:无权访问此服务器上的“\”。
什么是正确的方法来实现我想要的?
在RewriteRule之后不应该有一个[R] ,因为这会告诉Apache发送302redirect,而不是在内部重写URL。
RewriteRule的第二部分应该以斜杠开始,除非它在目录上下文中(例如在.htaccess文件或<Directory >块中)。 如果没有斜杠,则会将URL重写为http://example.comnl/index.php而不是http://example.com/nl/index.php 。
RewriteEngine On RewriteCond %{REQUEST_URI} !^/en.* RewriteCond %{REQUEST_URI} !^/nl.* RewriteRule ^(.*)$ /nl$1 [L]