How to use htaccess to redirect to a new domain with different url structure

I’m trying to do a redirect from an old site to a new one:

OLD: blog.example.com
NEW: www.example.com/blog

Read More

To achieve the above, I got this .htaccess:

RewriteCond %{HTTP_HOST} ^blog.example.com$ [OR]
RewriteCond %{HTTP_HOST} ^blog.example.com$
RewriteRule (.*)$ http://www.exmaple.com/blog/$1 [R=301,L]
RedirectMatch 301 ^/bournemouth-datacentre/$ http://www.example.com/blog/

And that works fine. On top of that I need to redirect (example):

OLD: blog.example.com/somecategory/some-title-here/

NEW: www.example.com/blog/some-title-here

Note that I’m loosing the category in between domain and title and replacing it with blog. That’s fine.

Can anyone suggest how I can achieve both the subdomain to domain followed by blog redirect as well as the category redirects?

IMPORTANT: Old site is WP, new is Drupal!

Thanks!

Related posts

2 comments

  1. You can use:

    RewriteCond %{HTTP_HOST} ^blog.example.com$
    RewriteRule ^(?:bournemouth-datacentre|general|london)/(.*)$ http://www.example.com/blog/$1 [L,NC,R=301]
    
    RewriteCond %{HTTP_HOST} ^blog.example.com$
    RewriteRule ^(.*)$ http://www.exmaple.com/blog/$1 [R=301,L]
    
  2. Try the following code:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^blog.example.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^blog.example.com [NC]
    RewriteRule ^(.*)$ /bournemouth-datacentre/$1 [L,R=301,NC]
    

Comments are closed.