.htaccess website redirect

I’m tired of always searching the web for an .htaccess redirect when I need it, so now I need only to search my blog.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^from.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.from.com [NC]
RewriteRule ^(.*)$ https://to.com/$1 [L,R=301,NC]
  • from.com should be replaced with the site people will be coming from.
  • to.com should be replaced with the site people will be redirected to.

What the code does

  • Targets the old site in its entirety
  • Redirects all links to the new site

My usage example

I’m using this for a simple redirect of LemonLively.comLemonAndLively.com.

LemonLively.com/about will take you to LemonAndLively.com/about/ whether you use https:// or not.

Buy me a lemonade or check out my Everything Page.

Leave a comment