Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Question about .htaccess and redirects

Hey, all!

I have a question about redirecting using a site's .htaccess file.

I have a site that we have redesigned (both on WordPress), but both use different domains. We are going to redirect all traffic from the old site to the new one, but I'm having problems trying to set up the .htaccess file.

For instance, the blog post titles are the same since they were imported from the old site, but how would I write my RewriteRules for this?

The old one uses this structure:

http://www.oldsite.com/blog-post-title

but the new one uses this structure, which we want to keep:

http://www.newsite.ca/blog/blog-post-title

Can anyone offer any insight on how to write my rules?

3 Answers

For redirecting the entire site, you'll have to implore the Apache Rewrite rules.

# Redirect all pages from oldsite.com
# to newsite.ca/blog
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.oldsite.com$ [OR]
RewriteCond %{HTTP_HOST} ^oldsite.com$
RewriteRule ^(.*)$ http://www.newsite.ca/blog/$1 [R=301,L]

An additional option, but then means you are plugin dependent, is WP htaccess Control https://wordpress.org/plugins/wp-htaccess-control/

I remember that I did that once, I wrote it on my old website: http://oritzio.com/redirect-all-your-domain-to-another/

Wonderful, thank you both for this information! I'll give it a try and see how I make out. :)

Did that solve it for you??