RewriteRule forces the page to reload twice

I generated 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 am faced with some strange problem, which is in every request that causes the page to load internally twice, which leads to the problem that the db actions and email dispatch are also executed twice.

Does anyone have any ideas regarding this?

Thanks in advance!

Note 1: All requested resources are valid and available in accordance with browser resource tracking.

Note 2: There may be a problem in saving and subsequent processing of PATH_INFO? (/index.php/$1 => /index.php/foo/bar / ...)

+6
source share
3 answers

A rewriting engine cannot run a single HTTP request twice . It sends an HTTP request for Apache to either a static file, or a proxy function, or to a module (e.g. PHP) with a request change. But he cannot clone the request and give it 2 times apache.

If you have a β€œrun twice” problem, it is likely that you hit the empty URL of the image URL . In fact, this is not a mistake in the HTML version (at least until HTML5) and the features of url analysis.

If you get an empty GET url somewhere, HTML indicates that the browser should re-send the same request (the one that gave it the current page) with the same parameters. This can be done with a POST request 2 times (if the requested 1st page was POST). So where are these empty get url? In most cases, you get:

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

or

 url() (in the css) 

or

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

Read also @Jon answer favicon request. You should always check the result without browser behavior using wget or telnet requests.

Update: The detailed explanations and observations available on this blog with HTML5 add-ons that should remove this behavior for modern browsers.

+8
source

I had the same problem (or so I thought). This was caused by a request to favicon.ico, which I did not address in my rewrite rule.

+1
source

I had the same problem caused by rewriting the url and the script was loading twice, due to the fact that I did not add this:

 RewriteRule ^(js|img|css|favicon\.ico)/ - [L,QSA,S=2] 

This will stop the script from loading twice; he solved my problem.

+1
source

Source: https://habr.com/ru/post/887704/


All Articles