Redirect only home page to another site. not sub pages. example.com to newsite.com using .htaccess

I want to redirect home page alone. But not the sub links. I tried with the following code, but it not works.

   RewriteCond %{REQUEST_URI} ^/[/]?
   RewriteCond %{REQUEST_URI} !^/+[/]?
   RewriteRule (.*) http://www.newdomain.com/ [R=301,L]

So my requirement is,

Read More

When user access : http://test.site.co.uk then should redirected to http://newsite.co.uk

When user access : http://test.site.co.uk/mypage then should redirected to http://newsite.co.uk/mypage

Related posts

3 comments

  1.     RewriteEngine On
        RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
        RewriteRule ^(.*)$ http://www.example.com/ [L,R=301]
    
  2. You can use following rewrite rule :-

    RewriteCond %{HTTP_HOST} ^(example.com(/{0,1})){1}$
    RewriteRule http://example2.com(/{0,1}) [R=301,L]
    

    That (/{0,1}) part is for matching both example.com and example.com/ (but nothing esle) – if you do not wish to match example.com/ remove that part from both rows.

Comments are closed.