0

一个过时的 Wordpress 图片插件给我留下了超过 4000 404 个错误。

为了解决这个问题,我想批量 301 重定向数千个旧附件链接 URL 以指向原始源图像文件:

给出 404 错误的旧 URL 如下所示:

http://www.hongkonghustle.com/?pagename=album&?pp_album=main&pp_cat=default&pp_image=zombie_boy_tattoo_lady_gaga_rick_genest.jpg

我想将它们分别重定向到文件实际存在的 wp-content/photos 目录:

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

根据我的阅读,我相信我应该更改我的 htaccess 文件并使用 {QUERY_STRING} 添加 RewriteCond 但我不知道具体如何。

另外,我应该把相对于我当前 htaccess 的更改放在哪里?

我当前的 htaccess 文件包括以下内容:

Options +Indexes
Options +FollowSymLinks
RewriteEngine on
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 

再次感谢阿努巴瓦!你越来越近了!

现在它转到 /wp-content/photos/ 目录,但 URL 仍然不正确:

hongkonghustle.com/wp-content/photos/&/?pagename=album&%253fpp_album=main&pp_cat=default&pp_image=zombie_boy_tattoo_lady_gaga_rick_genest.jpg

我们需要最终的 URL 是:

hongkonghustle.com/wp-content/photos/zombie_boy_tattoo_lady_gaga_rick_genest.jpg

所以,hongkonghustle.com/wp-content/photos/IMAGE_FILENAME.JPG

我想它几乎解决了!如果您对如何完成此操作有任何想法,请更新我。真诚的感谢!

4

2 回答 2

1

我最终在 htaccess 中进行了这样的 301 重定向:

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
于 2013-10-15T05:51:03.323 回答
0

将您的代码更改为:

Options +Indexes +FollowSymLinks -MultiViews

RewriteEngine on
RewriteBase / 

RewriteCond %{QUERY_STRING} (^|&)pp_image=([^&]+) [NC]
RewriteRule ^$ /wp-content/photos/%1 [R=301,L]

RewriteCond %{HTTP_HOST} ^hongkonghustle\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^ %{REQUEST_URI}/ [L,R=301]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>    
# END WordPress 

<Files wp-config.php>
Deny from all
</Files>

IndexOptions -FancyIndexing  
于 2013-10-12T15:02:40.373 回答