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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
abatinCommented:
Use below code in your default php file
Remove other tags
<html>
<?php
   header( 'Location: http://www.newwebsite.com/mainpage.html' ) ;
?>
</html>
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dido123Author Commented:
Awesome .. it works! :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Networking

From novice to tech pro — start learning today.