4

My site url is www.testing.com and there is another site www.testing.com/newsite.

I want everyone who hits www.testing.com/newsite to be redirected to www.newsite.com

Unamata Sanatarai
  • 6,475
  • 3
  • 29
  • 51
Piyush Kumar
  • 85
  • 1
  • 9

4 Answers4

5

So simply add below line at index page.

header("Location: http://www.testing.com", false, 301);
exit;

Or write it in common file that are included in every page.

make sure there is http:// in header location other wise it will look for directory.

And also put exit; at the end so other code will not execute.

because sending header will not terminate script execution.

--EDIT-- it should be 301 to make it last forever

Unamata Sanatarai
  • 6,475
  • 3
  • 29
  • 51
Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90
  • 2
    Disadvantage of this is that you need to make an index file in the newsite folder. A better way is to use .htaccess and redirect it from there. – S.Visser Mar 15 '13 at 11:18
2

If you have a directory /newsite then place a .htaccess inside that directory with:

RewriteEngine On
RewriteRule ^.*$ http://www.newsite.com/ [R=301,L] 

However if you directed the newsite.com into the /newsite directory, then you need what Sankalp Mishra wrote in his answer. (but with newsite instead of testing)

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^newsite$ http://www.newsite.com/ [R=301,L]
Community
  • 1
  • 1
Unamata Sanatarai
  • 6,475
  • 3
  • 29
  • 51
0

Write header like:

  header("Location: http://www.testing.com"); 

on the home page of http://www.testing.com/newsite

for more about header

Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90
sandip
  • 3,279
  • 5
  • 31
  • 54
0

Use this in htaccess

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^newsite.*$ http://www.testing.com/ [R=301,L]
Engineer
  • 5,911
  • 4
  • 31
  • 58