Redirecting my website to another url

Hi,

I want to redirect my domain to another url. I want any request will be made on my domain to be redirected. EX:

www.website1.com redirects to www.website2.com/mypage/
website1.com redirects to www.website2.com/mypage/
www.website1.com/anything/1.html redirects to www.website2.com/mypage/
website1.com/anything/ redirects to www.website2.com/mypage/

I hope you got what I meant. Currently website1.com is hosted on my server.


Thank you so much for the help.
Dido123Asked:
Who is Participating?
 
Avinash ZalaWeb ExpertCommented:
You can do like this:


RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.website1.com$ [OR]
RewriteCond %{HTTP_HOST} ^website1.com$
RewriteRule ^(.*)$ http://website2.com/newpage [L,R=301]


Hope this helps,
Addy
0
 
mziterCommented:
Most of the time you can set that up through your hosting company/control panel.

Also, you can use code on the actual page. What code are the pages written in?

You can put the code below in between your head tags (<head> PUT HERE </head>) on the pages you want redirected also.
<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.website2.com/mypage">

Open in new window

0
 
Ante0Commented:
You could put a index.php on the root of website1.com
and place in it
<?php
header('Location:http://www.wwebsite2.com/mypage/');
?>

same in website1.com/anything/
but alter the Location for your needs.
0
Network Scalability - Handle Complex Environments

Monitor your entire network from a single platform. Free 30 Day Trial Now!

 
abatinCommented:
Use below code in your default php file
Remove other tags
<html>
<?php
   header( 'Location: http://www.newwebsite.com/mainpage.html' ) ;
?>
</html>
0
 
Dido123Author Commented:
I know of all these suggestions. The only problem with these suggestions is if someone hits www.website1.com/anypage/ or website1.com/oldpage.html instead of www.website1.com/index.html he will hit 404 page.

website1.com used to be a website so it has several old pages. All what I want is to redirect any request will website1.com to website2.com/mypage/ ... I'm pretty sure .htaccess file will be the option but I don't know what I should write in it.

0
 
abatinCommented:
Write below code in htaaccess file, it will redirect all to example.com, whatever the traffic is
Redirect 301 / http://www.website2.com/
0
 
Avinash ZalaWeb ExpertCommented:
Write this in your .htaccess file of website1


RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^website1.com [NC]
RewriteRule ^(.*)$ http://website2.com/anypage$1 [L,R=301]


Hope this helps
Addy...
0
 
Dido123Author Commented:
@abatin your line is working fine but there is a problem.

Let's say the line is : Redirect 301 / http://www.website2.com/yes/

When I request www.website1.com/no123/ it redirects to http://www.website2.com/yes/no123/

I want it to redirect to http://www.website2.com/yes/ no matter what I requested.
0
 
Avinash ZalaWeb ExpertCommented:
Have u tries  my code in .htaccess file????


Addy
0
 
Dido123Author Commented:
Yes Addy, but it always redirects to http://website2.com

I tried to set it as this but it didn't work :

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^website1.com [NC]
RewriteRule ^(.*)$ http://website2.com/realpage/$1 [L,R=301]

also

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^website1.com [NC]
RewriteRule ^(.*)$ http://website2.com/realpage$1 [L,R=301]


Both didn't redirect to http://website2.com/realpage/ or http://website2.com/realpage as I wanted.

I have no problem trying it again if you can solve this problem.

Thank you both for the help.
0
 
Avinash ZalaWeb ExpertCommented:
Try this:


RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.website1.com [NC]
RewriteRule ^(.*)$ http://website2.com/realpage$1 [L,R=301]


Hope this helps,
Addy
0
 
Dido123Author Commented:
Addy, I think you misunderstood me. I didn't mean I have a www and non-www problem.

I mean it doesn't redirect to the correct directory.

The link I want to redirect to is : www.website2.com/newpage/

All what I want is, If any visitor no matter what he writes he will be redirected to www.website2.com/newpage/

EX: If he visited,

website1.com
www.website1.com
website1.com/oldiee/
website1.com/old-index.html
Whatever etc...

He will be redirected to www.website2.com/newpage/

Your current code only redirects to www.website2.com ... not including the directory /newpage/

I hope my question is more clear now ...

Thank you so much for your time.
0
 
Avinash ZalaWeb ExpertCommented:
ok
Try this:


RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.website1.com [NC]
RewriteRule ^(.*)$ http://website2.com/newpage [L,R=301]


Hope this helps,
Addy
0
 
Dido123Author Commented:
OK .. now we're talking! :)

It's exactly like I want it. One more question.

I had to duplicate your code so I can assure it's working with both www or non-www

Because If I did like this :

RewriteCond %{HTTP_HOST} ^www.website1.com [NC]

non-www wouldn't redirect and vice-versa. I duplicated the code for non-www but I thought there might be one code that will work with both www and non-www

Addy, the 500 points is defiantly yours.
0
 
Dido123Author Commented:
Awesome .. it works! :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.