Chris
Chris

Reputation: 11

301 Redirect From One Domain/Directory to a New Domain outside of a directory?

I've never done this before and need to make sure I don't mess it up.. add that to the fact that I hardly know what I am doing, and I am a bit stressed out over this.

I have a Drupal site that needs to redirect to a WP site. All of the posts in a particular category will need to redirect to the WordPress site... but they will not be redirecting to a particular category or directory.

Knowing what I know about robots.txt files (which are likely totally different), I am thinking this would look like this: old.domain.com/latest-posts/* redirects to new.domain.com/

Another example would be: old.domain.com/latest-posts/post-blog-title redirects to new.domain.com/post-blog-title

Whats the best way of doing this? Theres tons of options.. editing an htaccess file seems simple enough as long as I know what needs to be added. I've been referred to regex a bunch when researching this and regex makes me nervous for some reason.

Reference: https://moz.com/learn/seo/redirection https://www.semrush.com/blog/301-redirect-htaccess/

Upvotes: 1

Views: 62

Answers (1)

Amit Verma
Amit Verma

Reputation: 41249

You can use the following redirect in your htaccess file :

RewriteEngine On

RewriteCond %{HTTP_HOST} ^old\.example\.com$ [NC]
RewriteRule ^latest-posts/(.*)$ https://new.example.com/$1 [L,NC,R=301]

This will 301 redirect all your latest-posts URLs to the new domain , ie: olddomain.com/latest-posts/foo-bar to newdomain.com/foobar . Make sure to place this code at the top of your htaccess, and if you use WordPress then this code must be placed before the wp-rewrites in htaccess.

You can also use a simple 301 redirect instead of the above RewriteRule if the newdomain is on a different server or it's pointing to a different document root on the same server

 Redirect 301 /latest-posts/ https://newdomain.com/

Upvotes: 1

Related Questions