重写规则将导致重新加载页面的两倍 [英] RewriteRule causes page to reload twice

查看:156
本文介绍了重写规则将导致重新加载页面的两倍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我形两种不同的RewriteRules为我的网页:

I shaped two different RewriteRules for my page:

# Enable URL Rewriting
RewriteEngine on

# exclude followed stuff
RewriteRule ^(js|img|css|favicon\.ico|image\.php|anprobe|content|libs|flash\.php|securimage)/ - [L,QSA,S=2]

# conditions (REQUEST dont point @ file|dir|link)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-F
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

# rules
RewriteRule ^(?!index\.php)brillen/(.*(brillen)|360|neu)/(.*)([a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}(?!\.))(.*)$     /index.php/brillen/$1?art_id=$4&$5&%{QUERY_STRING}      [NS,QSA,L]
RewriteRule ^(?!index\.php)(.*)$                                                            /index.php/$1                                   [NS,QSA,L]

......,我遇到一个奇怪的问题,而在于每个请求导致内部页面加载两次,这导致了数据库操作和邮件调度也执行了两次的问题。

... and I'm encountering a strange problem, which lies in every request causing the page internally to load twice, which leads to the problem that db actions and email dispatching are also executed twice.

有没有人有关于这种想法?

Does anyone have an idea concerning that?

在此先感谢!

注意1:所有请求的资源是有效的,可以根据浏览器的资源跟踪

Note 1: All requested resources are valid and available according to the browser's resource tracking.

注意2:五月的问题,保留和后处理的PATH_INFO产生的? (/index.php/$1 => /index.php/foo/bar /...)

Note 2: May the problem originate in retaining and post-processing the PATH_INFO? (/index.php/$1 => /index.php/foo/bar/...)

推荐答案

重写引擎的不能使一个HTTP请求运行两次。它的路线为Apache HTTP请求到一个静态文件,代理功能或模块(如PHP)与请求改变。但它不能克隆的要求,并给它的2倍到Apache。

The rewrite Engine cannot make a single HTTP request run twice. It routes the HTTP request for Apache to either a static file, a proxy function, or a module (like PHP) with alteration in the request. But it cannot clone the request and give it 2 times to apache.

当您有任何跑两次的问题有机会,你是在空的​​图像URL错误击中。事实上这不是真的是HTML(至少前HTML5)的功能中的错误和URL解析的功能。

When you have any "run twice" problem chances are that you are hit by the empty image url bug. In fact it's not really a bug it's a feature of HTML (at least before HTML5) and a feature of url-parsing.

如果你得到一个地方的空的​​GET网址,HTML指出,浏览器应该重新发送相同的查询与相同参数(即给他的当前页面的那一个)。这可以使一个POST请求发生2次(如果被请求的第一页是一个POST)。那么,这些空的GET网址是什么?大多数时候,你可以:

If you get somewhere an empty GET url, HTML states that the browser should re-send the same query (the one that gave him the current page) with same parameters. This can make a POST request happen 2 times (if the requested 1st page were a POST). So where are these empty GET url? Most of the time you get either :

<IMG SRC="" ...> (in the HTML)

url() (in the css)

<script type="text/javascript" src=""></script>
<link rel="stylesheet" type="text/css" href=""> (in the HTML headers)

阅读还@乔恩回答有关图标查询。你应该总是通过使用wget或telnet 80查询测试的浏览器不行为的结果。

Read also @Jon answer about the favicon query. You should always test the result without browsers behaviours by using wget or telnet 80 queries.

更新:相关详细上的与HTML5增加这个博客应该删除现代浏览器的这种行为。

Update: detailled explanations and followups available on this blog with HTML5 additions which should remove this behavior for modern browsers.

这篇关于重写规则将导致重新加载页面的两倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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