Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess redirect to external URL while hiding redirect

I want to be able to redirect a domain pointed to my webhosting to an external domain.

For example, I have this in my .htaccess:

RewriteCond %{HTTP:Host} ^(?:www\.)?mydomain\.example$ 
RewriteRule ^(.*)$ http://myexternal.example/site [R=301,NC]

However, when I visit the domain, the URL in my address bar changes to http://myexternal.example/site.

How can I redirect without changing the URL?

Is there another way around this? Do I need to use a frame/iframe?

like image 219
Ben Hall Avatar asked Nov 27 '09 10:11

Ben Hall


2 Answers

Bit long ago, but I'll answer the question anyway for those who come here by Google (like me). The answer is really simple:

In your htaccess, remove the R=301 part (and the comma of course).

R=301 means you do it via a 301 redirect. You don't want that

like image 131
Luc Avatar answered Oct 23 '22 02:10

Luc


Either a single frame frameset, or an iframe with width/height set to 100%.

I'm not sure if framsets are supported in newer versions of HTML, but browsers still understand old versions anyway... but a single iframe is easy anyway.

<html>
<head>
<title>My Site</title>
<style>
body {
    margin: 0;
    padding: 0;
}
body, iframe {
    width: 100%;
    height: 100%;
}
iframe {
    border: 0;
}
</style>
</head>

<body>
<iframe src="http://example.com" />
</body>
</html>
like image 44
Matthew Scharley Avatar answered Oct 23 '22 01:10

Matthew Scharley