如何在wordpress中重定向图像?

时间:2018-01-31 07:47:30

标签: wordpress .htaccess

我有两个问题:

1)我正在尝试将图片从一个网址重定向到另一个网址,但它无法正常工作

2)我有一些图片现在不在我的网站上。当我尝试打开该网址时,它会重定向404 Not Found Nginx。我想将其重定向到主页。

我尝试过以下代码

###### BEGIN WP_OPTIMIZE_BY_XTRAFFIC_CONFIGS_WP-OPTIMIZE-BY-XTRAFFIC ######
Options -Indexes
###### END WP_OPTIMIZE_BY_XTRAFFIC_CONFIGS_WP-OPTIMIZE-BY-XTRAFFIC ######
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]
ErrorDocument 404 https://tabc.com (Not Working)
#Also Tried this, not working
RewriteCond %{REQUEST_URI} !(test\.html|\.png)$ [NC]
RewriteRule .* /tabc.com  [L]
RedirectPermanent /wp-content/uploads/image.gif http://www.tabc.com/path/ 
</IfModule>


# END WordPress

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php54” package as the default “PHP” programming language.
<IfModule mime_module>
  AddType application/x-httpd-ea-php54 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

1 个答案:

答案 0 :(得分:0)

# nginx configuration

location = /favicon.ico {
}

location / {
  if (!-e $request_filename){
    rewrite ^(.*)$ /index.php break;
  }
}

location /images/123.jpg {
  rewrite ^(.*)$ http://example.com/images/abc.jpg redirect;
}

您还应该阅读此https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/并使用此https://winginx.com/en/htaccess