1

我的 htaccess 重定向到自定义错误页面

例如:

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

我注意到,当我访问带有内部断开链接的页面时,该页面需要很长时间才能加载。

169 个请求 ❘ 562 KB 传输 ❘ 1.2 分钟(加载:1.2 分钟,DOMContentLoaded:2.31 秒)

如果我在 htaccess 中禁用所有带有 ErrorDocument 的行

169 个请求 ❘ 传输了 150 KB ❘ 3.46 秒(加载:3.12 秒,DOMContentLoaded:2.88 秒)

问题,为什么加载需要这么长时间?我怀疑每个断开的链接都会通过error.php?

如果是这种情况,有没有办法修改 .htacess 以忽略内部链接,只在加载时检查初始页面,或者没有办法做到这一点?

编辑:

这是一个调用 tpl (mypage.tpl) 的 php 页面 mypage.php,所以本质上对于浏览器来说这应该是一个 html。

在 chrome 中,当我注释掉 ErrorDocument 时,我可以看到每个断开的链接进展非常缓慢

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

编辑2。

我已经复制了源代码并只创建了 html 页面,但问题仍然存在。

但是我发现它并不总是发生而且它是间歇性的..我认为它可能与 CPU 负载有关但是只是检查了 cpu 使用率并且很低我也重新启动了 apache 但问题仍然发生最多的时代。

这是我的整个 .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 设置为 1

4

1 回答 1

1

首先,为丢失图像文件导致的 404 错误调用错误处理程序是没有意义的。我建议您通过在您的以下代码中仅调用.php文件的404 错误处理程序:mod_rewriteDOCUMENT_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]

然后在你的内部/ex/main/error.php确保在顶部有这一行,用于将传递的 HTTP 状态返回给浏览器

http_response_code($_GET['e']);
于 2013-09-25T12:09:39.377 回答