Skip to content

Instantly share code, notes, and snippets.

@plembo
Last active April 22, 2019 17:40
Show Gist options
  • Save plembo/9f2be0cd13055339dba13ee9e7ad3864 to your computer and use it in GitHub Desktop.
Save plembo/9f2be0cd13055339dba13ee9e7ad3864 to your computer and use it in GitHub Desktop.
Greediest Apache redirect

Greediest Apache Redirect

Sometimes you just have to make sure that anything going to an old site winds up on a designated page over at the new.

RewriteEngine On
RewriteRule /.* https://new.example.com/newhome [R=301,L]

The foward slash dot star is what makes this redirect matching rule the most greedy of all. The "R=301" flag forces an external redirect (to another host) and tells the browser it is permanent. The "L" flag marks this as the end of the rewriting process.

If the target page name is listed in DirectoryIndex in the target web server config, you don't have to include it.

See the documentation Apache mod_rewrite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment