2011-03-20 152 views
6

我剛剛從Drupal + Wordpress移至完全使用WordPress構建的網站。.htaccess將圖像從舊文件夾重定向到新文件夾

我已經有一組圖像,文件不再存在,需要嘗試將所有圖像保存在一個文件夾中(如果可能)。我需要發送http://www.domain.com/blog/wp-content/uploads/http://www.domain.com/wp-content/uploads的任何gif | png | jpg的請求。

如果有人可以幫助將不勝感激 - 我的.htaccess aint曾經是。在此先感謝

回答

0

請嘗試在你的.htaccess規則:

RewriteEngine On 
RewriteRule ^/blog/wp-content/uploads/(.+)\.(png|gif|jpg)$ wp-content/uploads/$1.$2 [QSA,L] 
0

試試這個

RewriteEngine on 

RewriteCond %{HTTP_REFERER} ^http://www.domain.com/blog/wp-content/uploads [NC] 

RewriteRule .* http://www.domain.com/wp-content/uploads [NC,L] 
0

你可以嘗試把這個

RewriteEngine ON 
RewriteRule ^/blog/wp-content/(.*)$ http://newdomain.com/wp-content/$1 [R=301,L] 
9

如果谷歌「 htaccess重定向「,頂部鏈接是這樣的:
http://www.htaccessredirect.net/

如果使用「301重定向目錄」一節中,你得到這個代碼:

//301 Redirect Entire Directory 
RedirectMatch 301 /blog/wp-content/uploads/(.*) /wp-content/uploads/$1 

據我所知目標域應該是絕對的,所以下面可能的工作:

//301 Redirect Entire Directory 
RedirectMatch 301 /blog/wp-content/uploads/(.*) http://www.domain.com/wp-content/uploads/$1 
+0

我有類似的問題,不太知道爲什麼我不能讓重寫規則語法的工作,但使用與上面類似的較舊的RedirectMatch正常工作。 'RedirectMatch 301 /old-folder/(.*)/ new-folder/$ 1' - 謝謝+1 – toyNN 2011-12-03 03:26:45

0

我對於.htaccess文件的所有重寫規則和重定向選項都討厭的是他們都依賴於硬編碼重定向的路徑(URI)和/或服務器。

「.htaccess」文件它應該是當前目錄的要點!它可以以許多不同的方式引用,安裝在不同位置的不同服務器上。因此,將其設置到特定位置以進行簡單的目錄重命名是不合邏輯的。

的解決方案是以某種方式結合當前URI(不考慮或其中「的.htaccess」位置)到結果......

這是我的位置獨立「的.htaccess」目前的解決方案重定向重命名子目錄,甚至我承認它並不完美......但它的作品...

Options +FollowSymLinks 
RewriteEngine On 
RewriteRule ^OLDdir/.*$   %{REQUEST_URI}::: [C] 
RewriteRule ^(.*)/OLDdir/(.*)::: $1/NEWdir/$2  [R,L] 
相關問題