2011-08-16 107 views
1

我工作了2个小时,但最后我放弃了。

我有2个条件:

1.如果用户请求一个PHP文件重定向CMS/index.php的请求= $ 1
2.如果用户请求的东西从PHP不同(PNG,CSS,JPG)重定向CMS /网站/ $ 1

第一条规则可行,但我无法适用第二条规则。当用户请求/cms/style.css时,Apache重定向cms/website/style.css并再次重定向cms/website/website/style.css并循环。htaccess重定向问题(循环)

我htaccess文件是这样的:

Options +FollowSymLinks 
RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule (.*\.php) /cms/index.php?request=$1 [L] 
RewriteRule (.*\.!(php)) /cms/website/$1 [R,L] 

注:我不知道这最后的正则表达式是真实的,还是不行。并返回500的error_log输出

"[Tue Aug 16 16:26:11 2011] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace." 
+0

Apache日志是很多的试验和错误的,所以很难得到肯定,但第二条规则看起来无限 - 如果它匹配。所有规则将在重定向('[R]')之后再次运行,因此'/ cms/website/$ 1'会再次匹配规则,然后再转发到'/ cms/website/cms/website/$ 1'等。 –

+0

@robin,实际上[RewriteLooping](http://wiki.apache.org/httpd/RewriteLooping)说如果我使用[R],它不能循环。但是,即使设置了此选项,它也会循环。 –

回答

1
Options +FollowSymLinks 
RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !(.*)\.php$ 
RewriteRule (.*)\.(.*)$ /cms/website/$1 [R,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} (.*)\.php$ 
RewriteRule (.*)\.php /cms/index.php?request=$1 [L] 
+0

谢谢!它工作,但我不明白问题是什么。你知道为什么[R,L]在我以前的htaccess中不起作用吗? –

+0

@burak emre不,我也有使用[L]旗的问题! – undone