.htaccessでの転送設定は、いつもその場で調べていることなので、備忘録的にまとめておこう。
大雑把には、
http://www.example.jp/ → http://www.example.com/
の転送を設定する方法。
◆すべてを1箇所にリダイレクト
RedirectMatch ^(.*)$ http://www.example.com/hoge/
例
http://www.example.jp/
http://www.example.jp/hoge/
http://www.example.jp/hoge/foo/
がすべて
http://www.example.com/hoge/
に転送される。
◆特定URL(ディレクトリ)配下以外をリダイレクト
RedirectMatch ~[/foo*] http://www.example.com/hoge/
http://www.example.jp/hoge/foo*
以外のすべてが
http://www.example.com/hoge/
に転送される。
※http://www.example.jp/hoge/foo* はそのままアクセス可能
◆別ドメイン(または別ディレクトリ)の同一階層のREQUEST_URIにリダイレクト
RedirectMatch ^(.*)$ http://www.example.com$1
http://www.example.jp/
http://www.example.jp/hoge/
http://www.example.jp/hoge/foo/
がそれぞれ
http://www.example.com/
http://www.example.com/hoge/
http://www.example.com/hoge/foo/
に転送される。
正規表現に一致するか次第なので、表現によっては複合することも可能。
No comments
Trackbacks
By submitting a comment you grant typista a perpetual license to reproduce your words and name/web site in attribution. Inappropriate and irrelevant comments will be removed at an admin’s discretion. Your email is used for verification purposes only, it will never be shared.