Whole domain 301 redirect with changing url

I’ve merged two websites (moved posts from old website to new one).
And I want to make permanent redirect to new website.
The problem is old website posts had this structure: “http://oldsite.com/page/“, but new site posts looks like this: “http://newsite.com/page.html“.

So I’ve wrote in .htaccess

Read More
RedirectMatch 301 (.*)/$ http://newsite.com$1.html

And it’s ok with particular posts, but when you try to reach root of http://oldsite.com/ you got redirect to http://newsite.com.html/

any help would be appreciated

Related posts

2 comments

  1. I fix my problem using 2 redirect rules, works for me now:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} oldsite.com [NC]
    RewriteCond %{REQUEST_URI} ^/$
    Rewriterule ^(.*)$ http://newsite.com/ [L,R=301]
    
    # for all other pages
    RedirectMatch 301 (.*)/$ http://newsite$1.html
    
  2. You can break this into 2 redirect rules:

    # for pages
    RedirectMatch 301 ^/([^.]*[^/])$ http://newsite.com/$1.html
    
    # for landing and other page
    RedirectMatch 301 ^(.*)/$ http://newsite.com$1/
    

Comments are closed.