RewriteRule causes page to reload twice

后端 未结 3 1876
傲寒
傲寒 2020-12-07 02:04

I shaped two different RewriteRules for my page:

# Enable URL Rewriting
RewriteEngine on

# exclude followed stuff
RewriteRule ^(js|img|css|favicon\\.ico|ima         


        
3条回答
  •  甜味超标
    2020-12-07 02:47

    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.

    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.

    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 :

     (in the HTML)
    

    or:

    url() (in the css)
    

    or:

    
     (in the HTML headers)
    

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

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

提交回复
热议问题