画像は画像サーバから読み込む時の設定 .htaccess、htmlの記述例
よく、画像サーバを別に立てて、そこから画像ファイルや、動画ファイルを呼んで表示することをします。
呼び出し側は.htaccessを一行書いてあげれば、簡単に設定できます。
via
- 最速最安WEB画像サーバ構築術 - nginx + ServersMan - 新・浅く広くをモットーに | 一人WEBサービス屋メモ
- ApacheのRewriteRuleで検索条件に^/がマッチしない場合がある理由 - Dマイナー志向
仕様
- http://exsample.com から http://img.exsample.jp の画像を呼び出す
- htmlのソース内にhttp://img.exsample.jpの文字を書かない
.htaccess の記述
http://exsample.com/.htaccess の記述
RewriteEngine On RewriteRule ^/?img/(.*) http://img.exsample.jp/img/$1 [R=301,L,QSA,NE]
html の記述
http://exsample.com/index.html の記述
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>トップ</title> </head> <body> <img src="/img/a.gif" alt=""> </body> </html>
これで
http://img.exsample.jp/img/a.gif が呼び出される