Dot-Htaccess
僅當使用 .htaccess 不存在圖像時才重寫
僅當此目錄中的文件不存在時,如何使 RewriteCond+RewriteRule 將 site1.com/folder1 更改為 site2.com/folder1。例如:site1.com/wp-content/uploads/2014/03/image.jpg
如果圖像 site1.com/wp-content/uploads/2014/03/image.jpg 不存在,則獲取 site2.com/wp-content/uploads/2014/03/image.jpg 但如果圖像存在,則不要不做任何事。
更新,這裡是我需要的程式碼,謝謝大家的幫助)
Options +FollowSymLinks RewriteEngine ON RewriteCond %{REQUEST_URI} "/uploads/" RewriteCond %{REQUEST_FILENAME} .*\.(jpeg|jpg|gif|png)$ RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.+) http://site2.com/$1 [L,R=301]
嘗試這樣的事情。
RewriteCond %{REQUEST_FILE} !-f RewriteRule ^(.*)$ http://site2.com/$1 [QSA,R,L]
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f # the above ignores any url for a file that exists on the site RewriteCond %{REQUEST_FILENAME} !-d # the above ignores any url for a directory that exists on the site RewriteRule ^(.*)$ http://[NEW_DOMAIN]/$1 [QSA,R,L] # Redirect to another site and remain the same URL