mod_rewrite:网页有一个redirect循环

我试图让他的主机名后面有一个参数,如下所示:

www.domain.com/parameter

出于这个原因,我已经设置了下面的rewriteRule,我想使用两个参数值:

RewriteRule ^(en|pt)$ /index.php?language=$1&%{QUERY_STRING} [L] 

工作正常! 虽然,我需要创build一个新的规则,redirect任何请求没有列出的参数。

出于这个原因,我认为这将工作:

 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !^(en|pt)$ RewriteRule ^(.*)$ /pt/$1/ [L,R=301] 

但不幸的是显示redirect循环。

我已经得到:

 http://hostname/pt/pt/pt/pt/pt/pt/pt/pt/pt/pt/pt/pt/pt/pt/pt/pt/pt/pt/pt/pt/pt// 

任何提示如何解决这个赞赏!

这是因为目录不是普通文件

http://httpd.apache.org/docs/current/mod/mod_rewrite.html (没有HTML DOM id的片段!最接近的一个是不相关的LA-U ,甚至应该是一个id="LA-F"不见了!)

您可以执行各种文件属性testing:

 '-d' (is directory) Treats the TestString as a pathname and tests whether or not it exists, and is a directory. '-f' (is regular file) Treats the TestString as a pathname and tests whether or not it exists, and is a regular file. 

假如你的configuration其余部分是正确的(我不确定添加结尾的斜杠是个好主意),你应该为!-d添加一个额外的条件:

 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^(en|pt)$ RewriteRule ^(.*)$ /pt/$1/ [L,R=301] 

另外,考虑切换到Nginx! 它不仅具有更通用的语法,而且还与相关文档有直接的联系,比如http://nginx.org/r/if

使用“-e”和“!-e”运算符检查文件,目录或符号链接是否存在;

%{REQUEST_URI}是紧随主机名的URIpath,因此它以正斜杠开头: /

 RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !^/(en|pt)$ RewriteRule ^.*$ /pt/$0/ [R=301,L]