Permanent & temporary Apache .htaccess redirect (301 & 302)

This .htaccess directive will redirect visitors to the homepage on the new site, the path gets left alone. So someone visiting http://my-old-site.com/some/deep/page/ will get redirected to http://my-new-site.com/some/deep/page/

Permanent (301) vs Temporary (302) redirect

If you want the redirect to be temporary, you can use a 302 status code instead of 301. This has the side effect that existing pages keep their ranking in search engines better when you remove the redirect later.

Redirecting specific pages

Redirect a specific file to a subfolder

Redirect a moved/removed file to a new location:


PHP date/time based redirect (embargo)

Sometimes you want to put a (new) site live at a specific time, or redirect users to a different page after a specific date or time (e.g. on an event site, after the event has started).

You can do this using .htaccess files, but a quick and easy way is to create a file, e.g. auto-redirect.php. Then include this file at the top of your existing PHP script, for example your WordPress theme’s functions.php or just in index.php.

Include the script:
include ‘auto-redirect.php’;