2016-09-12 206 views
0

我是newby在htaccess,請幫助,如果你可以。 我認爲我的任務很簡單。htaccess重定向到另一個域

我有一個網站,例如newsite.com。它是在wordpress上製作的。 而且我有這個網站的舊副本,在其他域上,例如oldsite.com

當我從oldsitenewsite一些圖片沒有轉移到newsite轉移的文件,但他們仍然對oldsite存在。

現在,當網頁加載時我就newsite檢查後縮略圖,如果在newsite不存在他們,我更換newsite網址oldsite網址。

但是有什麼辦法不只是更換newsite.com/image.jpgoldsite.com/image.jpg,但更換newsite.com/image.jpg,於,例如newsite.com/imgs/image.jpg,並在.htaccess文件生成規則,如果URL具有/IMGS/一部分,這意味着需要在尋找圖像oldsite.com/image.jpg

回答

0

我想你可以通過下面的.htaccess代碼

Options +FollowSymLinks 
RewriteEngine On 
RewriteBase/
RewriteCond %{HTTP_HOST} !^OLDDOMAIN\.com$ [NC] 
RewriteRule ^(.*)$ http://NEWDOMAIN.com [R=301,L] 

在新網站的HTML代碼

Options +FollowSymLinks 
RewriteEngine On 
RewriteBase/
RewriteRule ([^.]+\.(jpe?g|gif|bmp|png))$ http://www.newurl.com/imgs/$1 [R=301,L,NC] 
0

你可以把這個配置的虛擬主機的的文件中。

<VirtualHost *:80> 
     ServerName example.org 
     DocumentRoot /srv/redireccion 
     Redirect permanent/https://example2.org/ 
</VirtualHost> 
相關問題