LoginSignup
7

More than 5 years have passed since last update.

mod_rewrite で指定日時でリダイレクト先を切り替える

Posted at

httpd.conf や .htaccess に下記のように書く。2015年12月1日00:00:00までは / へのリクエストを /old/ に、それ以降は /new/ に飛ばす例。リダイレクト先を切り替えることを前提としているので、ステータスコードは 302 としている。

RewriteEngine On
RewriteCond %{TIME} <20151201000000
RewriteRule ^$ http://example.com/old/ [R=302,L]
RewriteRule ^$ http://example.com/new/ [R=302,L]

.htaccess に書いて DocumentRoot より下の階層に配置した場合、配置した場所へのアクセスをリダイレクトするようになる。たとえば、 http://example.com/latest/.htaccess に上記ファイルを配置した場合、 http://example.com/latest/ へのアクセスが振り分けられる。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7