【问题标题】:Wordpress fallback for 404 images404 图像的 WordPress 后备
【发布时间】:2021-02-23 06:23:41
【问题描述】:

如何为未找到的图像创建正确的 Wordpress(php) 404 后备。 JS方式不适合,因为SEO Auditors只解析html,还有404错误https://prnt.sc/vha4og

所以请不要建议这样的代码 - 它不能解决问题: <img src="<?php echo esc_url( $catalog_thumb_image['url'] ); ?>" onerror="this.src='https://site.md/wp-content/uploads/2018/07/logo.png'" alt="<?php esc_attr( the_title() ); ?>">

或者通过jquery

$('img').on('error', function() {
    $(this).attr('src', 'https://site.md/wp-content/uploads/2018/07/logo.png');
});

【问题讨论】:

标签: wordpress http-status-code-404 image-fallback


【解决方案1】:

好的 - 这是答案:

我们的主机混合使用了 nginx/apache,我认为我必须使用 nginx 规则(错误)。

.htaccess 有效,但我将代码放在底部而不是 .htaccess 的顶部。

RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule \.(gif|jpe?g|png|bmp) /logo.png [NC,L] 
# BEGIN
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END

【讨论】:

    猜你喜欢
    • 2014-02-21
    • 1970-01-01
    • 1970-01-01
    • 2015-08-24
    • 1970-01-01
    • 1970-01-01
    • 2018-03-31
    • 2020-12-28
    • 2011-08-13
    相关资源
    最近更新 更多