Welcome to WebmasterWorld Guest from 54.161.157.73

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Hidden redirect

The url in the address bar should remain as it was.

     
8:29 pm on Jul 12, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:June 1, 2005
posts:47
votes: 0


I want to redirect my visitors to another page with out letting them know that they are redirected. (The url in the address bar should remain as it was)

Would you please guide me how to do it?

8:32 pm on July 12, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 12, 2005
posts:371
votes: 0


Assuming you have mod_rewrite installed, you could put the following in an .htaccess file:

RewriteEngine On
RewriteRule ^test.html index.html [L]

When users attempted to access test.html, they would infact get index.html, without knowing that they were.

8:42 pm on July 12, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:May 16, 2005
posts:60
votes: 0


You can also use frames.

Filename: index.html

Code
=====
<html>
<head>
<title>Insert Title Here</title>
</head>
<frameset rows="0" frameborder="NO" border="0" framespacing="0">
<frame name="mainFrame" src="home.html" scrolling="AUTO" marginwidth="0" marginheight="0" frameborder="NO">
</frameset>
<noframes>
<body bgcolor="#FFFFFF" text="#000000">
</body>
</noframes>
</html>

Filename: home.html

Code
=====
<HTML>
<HEAD>
<META HTTP-EQUIV="refresh" CONTENT="0; url=http://www.url you want to load.com">
</HEAD>
<BODY>

</BODY>
</HTML>

Place these two files in the same folder.

Hope this helps!

8:48 pm on July 12, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 12, 2005
posts:371
votes: 0


Note that a savvy user could easily determine they were being redirected with a frame. Using the mod_rewrite, no user would have any idea. It depends on how transparent it needs to be to the user.
9:06 pm on July 12, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:June 1, 2005
posts:47
votes: 0


Thank you both.
But I prefere not to use frames.
9:11 pm on July 12, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:June 1, 2005
posts:47
votes: 0


My goal is to redirect [sub.example.com...] to http://www.example.com/a/b/
This is the code I used:

RewriteEngine On
RewriteRule ^ http://www.example.com/a/b/ [L]

But the url is also changing.

9:19 pm on July 12, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


If the two subdomains are separately hosted, then you'll have to proxy the request. Otherwse look carefully at the first response to your thread. It does not include "http://www.example.com" and this makes the difference.

Jim

9:22 pm on July 12, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 12, 2005
posts:371
votes: 0


There are actually 2 issues with how you're doing that:

1) If you only want to redirect [sub.example.com...] to the other site, and not any subpages (ie [sub.exmample.com...] then make sure you do "RewriteRule ^$ http://www.example.com/a/b [L]". Currently it will do everything, which may or may not be what you want.
2) Anytime you want to serve a page from a different domain, it will actually change the address. The only way to have it not change the address is to serve a page that's available on the current site.

9:50 pm on July 12, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:June 1, 2005
posts:47
votes: 0


sorry! But you know I'm getting a bit confused,
I want to redirect a virtual sub domain to a folder from the main domain
news.mysite.com to mysite.com/index.php/feed/

The main domain and the sub domain are not hosted separately. Actually the sub domain is only a folder on my root (named "news")

Now can I redirect news.mysite.com to mysite.com/index.php/feed/ some how hidden?

10:00 pm on July 12, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 12, 2005
posts:371
votes: 0


When defining a site or virtual site in apache, you specify a DocumentRoot. You can do a hidden redirect to any page underneath this that path. If you try to redirect to another site, it will change the address.

So news.example.com => www.example.com/index.php/news will change the address.

What you want to do is possible if mod_proxy is installed. To check this, find out where your httpd program is, and do a "httpd -l" to list the modules. If mod_proxy is in there, then you can change the end of your RewriteRule line to be [P] instead of [L].

If you do not have mod_proxy, then any page you redirect to has to be available from news.example.com. Hopefully this will clear things up a little

10:06 pm on July 12, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:June 1, 2005
posts:47
votes: 0


Thanks, thank you very much!
10:17 pm on July 12, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:June 1, 2005
posts:47
votes: 0


Ok, this is what I did and its working for me:

RewriteCond %{HTTP_HOST} news.example.com
RewriteCond %{REQUEST_URI}!index.php/news/
RewriteRule ^(.*)$ index.php/news/$1 [L]

10:20 pm on July 12, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 12, 2005
posts:371
votes: 0


Glad to hear you got it working, mod_rewrite is one of those crazy things that you usually have to guess, test, repeat for a while :)
12:03 am on July 13, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


One thing to note here is that you've done a server-internal *rewrite*; A redirect, by definition, changes the address bar because the server sends a 301 or 302 response to the browser, telling it to initiate a new HTTP request and re-request the desired resource from the new URL provided in the redirect response.

A rewrite, on the other hand, happens entirely within the server and within the current HTTP request, and simply substitutes a different file than the one associated with the URL that was requested.

It really helps to understand this point, and to use the terms "rewrite" and "redirect" as appropriate.

Jim

9:46 pm on July 13, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:June 1, 2005
posts:47
votes: 0


Thanks Jim, good point.