Pregunta

My htaccess redirects to custom error pages

e.g:

ErrorDocument 400 /ex/main/error.php?e=400
ErrorDocument 401 /ex/main/error.php?e=401
ErrorDocument 403 /ex/main/error.php?e=403

I have noticed that when I visit a page with internal broken links the page takes a very long time to load.

169 requests ❘ 562 KB transferred ❘ 1.2 min (load: 1.2 min, DOMContentLoaded: 2.31 s)

If I disable all the lines with ErrorDocument in htaccess

169 requests ❘ 150 KB transferred ❘ 3.46 s (load: 3.12 s, DOMContentLoaded: 2.88 s)

Question, why does it take so long to load? I suspect that is going through the error.php for every broken link ?

If that's the case is there a way to modify .htacess to ignore internal links and only check the initial pages upon load or there is no way to do this?

EDIT:

This is a php page mypage.php that calls a tpl (mypage.tpl) so in essence for the browser this should be an html.

In chrome I can see each of the broken links progressing very slowly when ErrorDocument is on when i commented out they go really fast

GET http://127.0.0.1/ex/main/upload/221/ 403 (Forbidden) mypage.php:1972
GET http://127.0.0.1/ex/main/upload/194/d76fca99d30206e23630543f636246e7.jpg 404 (Not Found) mypage.php:2004
GET http://127.0.0.1/ex/main/upload/187/b9187d74b1a622868610696c89b429c1.png 404 (Not Found) mypage.php:2016
GET http://127.0.0.1/ex/main/upload/186/d39bbfdc9045bfd0428d1a98ad9138e6.jpg 404 (Not Found) mypage.php:2028
GET http://127.0.0.1/ex/main/upload/185/7d9e6d8d6fd631cef897c8b0e455d1b3.jpg 404 (Not Found) mypage.php:2040
GET http://127.0.0.1/ex/main/upload/184/77b778a4551434ab4ebe10efc62290ee.jpg 404 (Not Found) mypage.php:2052
GET http://127.0.0.1/ex/main/upload/183/ 404 (Not Found) mypage.php:2072
GET http://127.0.0.1/ex/main/upload/182/719efc3b142ac927e9a19de7eed865d9.jpg 404 (Not Found) mypage.php:2084
GET http://127.0.0.1/ex/main/upload/181/0761ee3949228e14f667e4ecd75bb696.jpg 404 (Not Found) mypage.php:2096
GET http://127.0.0.1/ex/main/upload/180/ 404 (Not Found) mypage.php:2108
GET http://127.0.0.1/ex/main/upload/179/77e16dcc3419dc00342a2df1d71a565a.jpg 404 (Not Found) mypage.php:2120
GET http://127.0.0.1/ex/main/upload/177/cd3c32ad9392f61d0cadda7c8dccfefa.jpg 404 (Not Found) mypage.php:2132
GET http://127.0.0.1/ex/main/upload/172/d07c37c0413f85a6f4fbe5c852ae8a5e.jpg 404 (Not Found) mypage.php:2152
GET http://127.0.0.1/ex/main/upload/171/7d8be9ea82ce7908e9983010863e0bda.JPG 404 (Not Found) mypage.php:2164
GET http://127.0.0.1/ex/main/upload/170/a50e8f6dc3aa68355358dc80499aa876.jpg 404 (Not Found) mypage.php:2176
GET http://127.0.0.1/ex/main/upload/169/b15ea09c05357f4b6cdd640a5f753fc7.jpg 404 (Not Found) mypage.php:2188
GET http://127.0.0.1/ex/main/upload/168/54427a8d0a9bda54a85009d3ec8e5637.jpg 404 (Not Found) mypage.php:2200
GET http://127.0.0.1/ex/main/upload/167/ec38a378e0c7a574275facd0eaa94be3.jpg 404 (Not Found) mypage.php:2212
GET http://127.0.0.1/ex/main/upload/166/80592697b068d3fb5f763435e495b781.jpg 404 (Not Found) mypage.php:2232
GET http://127.0.0.1/ex/main/upload/140/ae2db3bacabf7ce24e124f4c412aa0a4.jpg 404 (Not Found) mypage.php:2244
GET http://127.0.0.1/ex/main/upload/126/babd6909334499074dcc00d9ba8bcd9b.jpg 404 (Not Found) mypage.php:2256
GET http://127.0.0.1/ex/main/upload/124/ 404 (Not Found) mypage.php:2268
GET http://127.0.0.1/ex/main/upload/122/e322c941a0f7ade3c2d71a873ff1ff78.png 404 (Not Found) mypage.php:2280
GET http://127.0.0.1/ex/main/upload/106/5adc33fc8a2ca65d90783727483f5016.png 404 (Not Found) mypage.php:2292
GET http://127.0.0.1/ex/main/upload/102/a3d2557f2845ebf8df3dc3e2678a2619.jpg 404 (Not Found) mypage.php:2312
GET http://127.0.0.1/ex/main/upload/101/7eb6b918c9831857f6ce02be6c1603b1.jpg 404 (Not Found) mypage.php:2324
GET http://127.0.0.1/ex/main/upload/94/cd47aeea746b8835a5e296511e42384c.jpg 404 (Not Found) mypage.php:2336
GET http://127.0.0.1/ex/main/upload/93/3058cf890c384265a22c065b4efe0538.jpg 404 (Not Found) mypage.php:2348
GET http://127.0.0.1/ex/main/upload/87/b4572d58eb659bfdd0e8fbfe39a70825.jpg 404 (Not Found) mypage.php:2360
GET http://127.0.0.1/ex/main/upload/82/fac774dfcd5d5b3cc6b0e0ab9cf5bf20.jpg 404 (Not Found) mypage.php:2372
GET http://127.0.0.1/ex/main/upload/80/891ca4ffae9470eb451ed4f938e280f4.jpg 404 (Not Found) mypage.php:2392
GET http://127.0.0.1/ex/main/upload/57/ 404 (Not Found) mypage.php:2404
GET http://127.0.0.1/ex/main/upload/56/ 404 (Not Found) mypage.php:2416
GET http://127.0.0.1/ex/main/upload/55/ 404 (Not Found) mypage.php:2428
GET http://127.0.0.1/ex/main/upload/54/ 404 (Not Found) mypage.php:2440
GET http://127.0.0.1/ex/main/upload/53/ 404 (Not Found) mypage.php:2452
GET http://127.0.0.1/ex/main/upload/52/ 404 (Not Found) mypage.php:2472
GET http://127.0.0.1/ex/main/upload/50/ 404 (Not Found) mypage.php:2484
GET http://127.0.0.1/ex/main/upload/49/ 404 (Not Found) mypage.php:2496
GET http://127.0.0.1/ex/main/upload/48/ 404 (Not Found) mypage.php:2508
GET http://127.0.0.1/ex/main/upload/46/ 404 (Not Found) mypage.php:2520
GET http://127.0.0.1/ex/main/upload/39/ 404 (Not Found) mypage.php:2532
GET http://127.0.0.1/ex/main/upload/36/ 404 (Not Found) mypage.php:2552
GET http://127.0.0.1/ex/main/upload/33/ 404 (Not Found) mypage.php:2564
GET http://127.0.0.1/ex/main/upload/27/bb7439252a1168e03b2068faac1ec4ba.JPG 404 (Not Found) mypage.php:2576
GET http://127.0.0.1/ex/main/upload/26/ 404 (Not Found) mypage.php:2588
GET http://127.0.0.1/ex/main/upload/25/ 404 (Not Found) mypage.php:2600
GET http://127.0.0.1/ex/main/upload/24/ 404 (Not Found) mypage.php:2612
GET http://127.0.0.1/ex/main/upload/23/ 404 (Not Found) mypage.php:2632
GET http://127.0.0.1/ex/main/upload/21/ 404 (Not Found) mypage.php:2644
GET http://127.0.0.1/ex/main/upload/85/ 404 (Not Found) mypage.php:2656

EDIT2.

I have copied the source code and created just the html page and the problem is still present.

However I have discovered that it doesn't always happen and it is intermittent..I was thinking that it might be have been relating to CPU load however just checked the cpu usage and is low also I have restarted apache but the problem still happens most of the times.

Here is my whole .htaccess

Options -Indexes  

    # serve custom error pages

    ErrorDocument 400 /ex/main/error.php?e=400
    ErrorDocument 401 /ex/main/error.php?e=401
    ErrorDocument 403 /ex/main/error.php?e=403
    ErrorDocument 404 /ex/main/error.php?e=404
    ErrorDocument 500 /ex/main/error.php?e=500
    ErrorDocument 503 /ex/main/error.php?e=503

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+ex/main/error\.php[\s] [NC]
RewriteRule ^ - [F]

RewriteLogLevel is set to 1

¿Fue útil?

Solución

First of all there is no point in invoking error handler for 404 errors caused by missing image files. I would advise you to invoke 404 error handler only for .php files by having this mod_rewrite code in your DOCUMENT_ROOT/.htaccess:

# All your ErrorDocument except 404
ErrorDocument 400 /ex/main/error.php?e=400
ErrorDocument 401 /ex/main/error.php?e=401
ErrorDocument 403 /ex/main/error.php?e=403
ErrorDocument 500 /ex/main/error.php?e=500
ErrorDocument 503 /ex/main/error.php?e=503

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# send it to /ex/main/error.php?e=404 if php file isn't found
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.php$ /ex/main/error.php?e=404 [L,NC,QSA]

Then inside your /ex/main/error.php make sure to have this line at the top for returning passed HTTP status to browser:

http_response_code($_GET['e']);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top