前期投资的mod_rewrite规则是造成index.php文件加载两次 [英] Frontloading mod_rewrite rule is causing index.php to load twice

查看:91
本文介绍了前期投资的mod_rewrite规则是造成index.php文件加载两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直工作在一个使用前端装载机来处理所有的请求项目(路由domain.com/args/go/here到的index.php?REQ = ARGS /去/这里),它的工作非常出色。 ..或者我应该说,我认为这没有 - 我最近增加了一个新的记录,并对其进行测试,我把一个测试日志消息中的index.php。此消息已被写入我的日志文件两次,每次我重新加载页面的时间,等等调试完毕后,我发现原因是我的.htaccess文件 - 不管出于什么原因,它加载的index.php两次,每次请求。

下面是我的.htaccess:

  RewriteEngine叙述在
的RewriteBase /网站/测试/ I路添加了这个后,我发现的bug
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI}!^指数\\ $ .PHP太#此。不工作
重写规则^(。*)$的index.php?ARGS = $ 1 [L]

我也试过:

  FallbackResource /site/beta/index.php

这两个不工作(的index.php只是不,如果你尝试去,比如说,127.0.0.1/site/beta/admin/controls/加载 - 但它确实,如果你只是去/指数.PHP),而且还加载了两次。

有没有人能帮助我吗?我在IRC花了几个小时,也没有人能想出奏效的解决方案。 (上述2个是唯一的建议)


解决方案

您完全地相信这是一个错误的mod_rewrite?如果启用RewriteLog具有高rewriteLogLevel文件(9)你看到同样的请求处理2次?

有关我每次看到相同的请求进行2次'我想到另一个陌生的网络信标时间:空IMG SRC错误

如果您有地方在HTML中

 < IMG SRC =>

或者在CSS中的一个(很难找到)答:

 网​​址()

然后,你明白了。 HTTP协议规定,一个空的GET URL(和CSS图像或URL()是一个GET隐含的要求)必须是相同的URL作为渲染原始页面的一个调用(它可以是一个POST,以及如果你得到你的页面作为POST请求)。

有真的很少数的理由有mod_rewrite的响应2次,以一个单一的请求。请与萤火虫或LiveHTTP请求,你并不总是在发送请求的index.php 2倍。或用Telnet的模式HTTP请求测试服务器,手工,因为这肯定会只发送一个请求。

I've been working on a project that uses a frontloader to handle all requests (Routing domain.com/args/go/here to Index.php?req=args/go/here), and it's worked very well... Or I should say, I thought it did - I recently added a new logger, and to test it I placed a test log message in index.php. This message was being written to my log file twice, every time I reloaded the page, and after much debugging I found the cause to be my .htaccess file - for whatever reason, it loads index.php twice for every request.

Here's my .htaccess:

RewriteEngine On
RewriteBase /site/beta/ #I added this after I discovered the bug
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^index\.php$ #This too. Doesn't work
RewriteRule ^(.*)$ index.php?args=$1 [L]

I've also tried:

FallbackResource /site/beta/index.php

Which both doesn't work (Index.php just doesn't load if you try to go to, say, 127.0.0.1/site/beta/admin/controls/ - but it does if you just go to /index.php), and still loads twice.

Is anyone able to help me? I spent a few hours in IRC, and no one could come up with a solution that worked. (The two above are the only ones suggested)

解决方案

Are you completly sure it's a mod_rewrite bug? If you enable RewriteLog file with a high rewriteLogLevel (9) do you see the same requests handled 2 times?

For me every time I see the 'same request done 2 times' I think about another strange web bug: The empty IMG src bug.

If you have somewhere in your HTML an

<IMG SRC="">

or in one of the css (harder to find) a:

url()

Then you've got it. HTTP protocol dictate that an empty GET url (and an image or url() in css is a GET implicit request) MUST be a call to the same url as the one which render the original page (and it can be a POST as well if you get your page as a POST request).

There're really few reason to have a mod_rewrite responding 2 times to one single request. Check with Firebug or LiveHTTP Requests that you're not always sending the index.php request 2 times. Or test your server with a telnet-mode HTTP request, by hand, as this will certainly send only one request.

这篇关于前期投资的mod_rewrite规则是造成index.php文件加载两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆