douquanjie9326 2013-10-11 12:19
浏览 62
已采纳

Wordpress:如何更改链接到图像源文件而不是附件链接?

For several years I used a Wordpress plugin called PhotoPress that was GUI to upload and place images in Wordpress posts. The plugin was discontinued in 2007 as Wordpress's own Media gallery greatly improved.

The trouble that I now have is that four or five years worth of images in my posts were uploaded using PhotoPress which attached the images to posts in a particular way that is different from the native Wordpress default.

When I switched to a new theme recently it caused a number of problems.

Looking at Google Webmastertools I have over 4000+ 404 errors due to bad links from this situation. (See URLs below)

Although images show up in the posts, if you click directly on any of the images in the older posts, instead of going to a page showing the image, it returns a 404 error. Please see the following:

The images appear correctly inside the post:

http://www.hongkonghustle.com/fashion/3138/thierry-mugler-hong-kong-china-fashion-show-western-market-hk-rick-genest-zombie-boy-rico-nicolas-formichetti-lady-gaga-stylist-joyce-boutique-store-skeleton-tattoo/

However, clicking on an individual image returns a 404 error.

The way that PhotoPress linked the image looks like this: /?pagename=album&?pp_album=main&pp_cat=default&pp_image=zombie_boy_tattoo_lady_gaga_rick_genest.jpg

Meanwhile, the directory path where the image source is actually stored is here:

http://www.hongkonghustle.com/wp-content/photos/zombie_boy_tattoo_lady_gaga_rick_genest.jpg

I'm not certain, but I think this is because the images are not linked to the source file directly - instead they are linked to the POST ATTACHMENT link.

I am very confused about how to fix this.

The images were originally (and still are) stored in wp-content/photos folder, so if you click the direct URL it works.

BUT, when I switched to my new theme, the images did not appear in the Media Library.

So I batch re-uploaded over 4000 images into the Media Library, and they are now sitting there unlinked.

I'm interested in a way of mass re-attaching the source images, and getting rid of the 404 errors.

How would I accomplish this?

Any thoughts? Your advice is greatly appreciated! Thanks!

  • 写回答

2条回答 默认 最新

  • dougourang1856 2013-10-15 05:44
    关注

    I ended up doing a 301 redirect in htaccess:

    Options +Indexes
    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond  %{QUERY_STRING}  ^pagename=album&\??pp_album=main&pp_cat=default&pp_image=(.*)$
    RewriteRule .* /wp-content/photos/%1? [L,R=301]
    
    RewriteCond %{HTTP_HOST} ^hongkonghustle\.com
    RewriteRule ^(.*)$ http://www.hongkonghustle.com/$1 [R=permanent,L]
    
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ http://www.hongkonghustle.com/$1/ [L,R=301]
    
    RewriteEngine On  
    RewriteBase / 
    <Files wp-config.php>
    Deny from all
    </Files>
    
    <Files wp-config.php>
    Deny from all
    </Files>
    Options +Indexes
    IndexOptions -FancyIndexing
    
    
    # BEGIN WordPress
    <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 WordPress
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度