2013-10-12 92 views
0

過時的Wordpress圖像插件給我留下了超過4000個404錯誤。批次301使用htaccess從動態URL重定向到靜態頁面

爲了解決這個問題,我想批301重定向幾千年附件鏈接URL來對原始的源圖像文件指出:

的舊網址,讓一個404錯誤是這樣的:

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

我想他們每個重定向到的wp-content /照片文件所在的目錄實際存在:

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 

再次感謝Anubhava!你越來越近了!

現在轉到/可溼性粉劑內容/照片/目錄,但該網址仍是不正確?

hongkonghustle.com/wp-content/photos/ & /網頁=專輯&%253fpp_album =主& pp_cat =默認& pp_image = zombie_boy_tattoo_lady_gaga_rick_genest.jpg

我們需要最終的網址是:

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

因此,hongkonghustle.com/wp-content/photos/IMAGE_FILENAME.JPG

我認爲它幾乎解決了!如果您對如何完成此操作有任何想法,請更新我。真誠的感謝!

回答

1

最後我做301重定向像這樣的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 
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 
+0

請不要把代碼中的註釋,它不是可讀。通過編輯將其添加到您的問題中。 – anubhava

+0

謝謝!對不起!會做。 –

+0

嗨Anubhava,恐怕我給你提供了不完整的信息。我原本從#BEGIN Wordpress中刪除了當前htaccess文件中的所有內容。我嘗試添加您提到的htaccess,但導致內部服務器錯誤。這可能是由於我提供給您的信息不完整。再次感謝您的輸入!非常感謝。 –