Welcome to WebmasterWorld Guest from 54.226.189.112

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Hidden redirect

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

     

virtuals

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

10+ Year Member



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?

ChadSEO

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

10+ Year Member



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.

thinkaholic

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

10+ Year Member



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!

ChadSEO

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

10+ Year Member



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.

virtuals

9:06 pm on Jul 12, 2005 (gmt 0)

10+ Year Member



Thank you both.
But I prefere not to use frames.

virtuals

9:11 pm on Jul 12, 2005 (gmt 0)

10+ Year Member



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.

jdMorgan

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

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



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

ChadSEO

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

10+ Year Member



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.

virtuals

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

10+ Year Member



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?

ChadSEO

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

10+ Year Member



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

virtuals

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

10+ Year Member



Thanks, thank you very much!

virtuals

10:17 pm on Jul 12, 2005 (gmt 0)

10+ Year Member



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]

ChadSEO

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

10+ Year Member



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

jdMorgan

12:03 am on Jul 13, 2005 (gmt 0)

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



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

virtuals

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

10+ Year Member



Thanks Jim, good point.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month