• Skip to primary navigation
  • Skip to main content
  • Skip to footer

BobbyVoicu.com

Curious about stuff

  • Home
  • About Me
  • Blog / Archive
You are here: Home / Learn to program / htaccess 301 redirects

htaccess 301 redirects

May 22, 2021 By Bobby Voicu

I’ve moved a lot of the sites over years from one domain to another, but I never remembered the htaccess redirect rules to do it. I always needed to search for them, sometimes finding different solutions that were never perfect.

Anyway, here are some of them, in case I need them again. I took them from this site, which has a lot more situations sorted out through redirects.

How do you redirect an entire site or domain to a new one?

Redirect 301 / http://www.domain.com/

How do you use rewriting to redirect from an old domain to a new domain?

RewriteEngine on
RewriteBase /
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

How do you use rewriting to redirect from a non-www to a www subdomain?

RewriteEngine on
RewriteBase /
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

From here: Common Htaccess 301 Redirect Rules.

◀Interviewing
Yahoo! sold for less than $5B▶

Filed Under: Learn to program, Misc

>>> If you want to continue the conversation, email me at me at bobbyvoicu dot com

Bobby Voicu

Bobby Voicu writes here from time to time.

Footer

About

I write about things that raise my curiosity. And I’m quite curious about all kinds of things.

For a full “About Me”, go here.

Recent Posts

  • My Bluesky ID: @bobbyvoicu.com
  • Batman is Here, on the Quest – XR Industry News of the Week – Oct. 24
  • XR Industry News of the Week – Oct. 10
  • XR Industry News of the Week – Oct. 4
  • XR News of the Week – September 14th, 2024

Friends

  • Sami the Westie
  • XR Gamer Digest

The CEO Library Collections

  • Best Leadership Books
  • Best Productivity Books
  • Women Entrepreneur Books

Copyright © 2025 · Privacy Policy · Disclaimer

We use cookies to enhance your experience. By clicking "Ok" or by continuing to use the site, you agree to this use of cookies and data.