Web Developememt Bug: Page Loads Two Times (PHP ASP HTACCESS)

Your page loads multiple (in my case two or three) times and you don’t know why. Maybe you noticed this when your database was being hit too often or you have duplicate records showing up on INSERTs. This might have been limited to Webkit browsers like Safari or Chrome, or maybe you saw it in Firefox as well.

In any case, here’s the solution to your webpage loading multiple times. And it’s really stupid.

First of all check if these lines are in your .htaccess file. If so, your solution follows – look no further.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]

What does the code do? It checks to see if a file is available where the ‘REQUEST_FILENAME’ is, and if it isn’t available your index.php will be loaded. This is so that you can use your Front Controller (everything goes through that), but if a file actually does exist (like an image, a stylesheet or basically anything), it can be successfully served.

But it also means that all requests will be affected by this .htaccess setting – ALL REQUESTS. There are two common problems that bring about this error and they’re both based on the above code.

  1. There is a <img src=”> link somewhere in your code. Your browser tries to load ” (which translates to root, e.g. www.yourdomain.com/). So, your page is loaded twice. Keep in mind that it could also be any other autoloaded srcs, such as scripts or stylesheets, that are not being correctly found.
  2. And if that isn’t your problem, it’s even stupider. Have you set a favicon? No? Then when your browser tries to autoload it, it’s redirecting to root (as above) and your page is loaded twice. Isn’t that fantastic? Anyway, set a favicon (that exists, even if it’s just a black square), and your problems will be solved.

That’s right, all that trouble because you didn’t put:

<link rel=”icon” type=”image/png” href=”/images/favicon.png” />

I hope that resolved your page loading multiple times error. It’s freaking annoying. I have another coming up about SQL Foreign Keys.

10 thoughts on “Web Developememt Bug: Page Loads Two Times (PHP ASP HTACCESS)”

  1. Ha! Have you ever had one of those days where everything is against you, and then you find out your script is being loaded multiple times per page load, breaking a captcha form? Yeah… I was having one of those. Then I read this post, face-palmed, and fixed my favicon link. What a dunce move – haha! Oh well, thanks for snapping me out of my funk.

  2. Pingback: URL

  3. Pingback: Google

  4. Pingback: Google

  5. Pingback: Google

  6. Pingback: australia dating site 100% free

  7. Pingback: Google

Leave a Comment

Your email address will not be published.