Website: Walter Gregg

Why .htaccess redirect fails

From time to time you may need to redirect a specific page from your site to a new subdomain. Say the old page is example.com/stuff/hypothetical.htm. It was advertised as example.com/stuff/hypothetical. You now want to advertise it as hypothetical.example.com. So you have created that subdomain and put a copy of the document there as index.htm.

The new address is working. But you need to cast a spell so that the old address will redirect to the new one. So you put your spell in example.com/.htaccess:

redirect 301 /stuff/hypothetical http://hypothetical/example.com/

But your spell doesn't work. Why? It took me a couple of days to uncover two unwritten rules about these incantations:

  1. When linking to your own subdomain's root page, you have to include that trailing slash. The spell will not work without it.
  2. You also have to remove the old document. If the server finds a document at the old URL, it serves it up notwithstanding the redirect.

Why .htacces redirect fails (Nov. 2015) (available at ) © W. Gregg 2015; CreativeCommons.org /licenses /by-nc-sa /4.0.

 No Privacy