homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

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

 8:29 pm on Jul 12, 2005 (gmt 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 Jul 12, 2005 (gmt 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 Jul 12, 2005 (gmt 0)

You can also use frames.

Filename: index.html

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

Filename: home.html

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


Place these two files in the same folder.

Hope this helps!


 8:48 pm on Jul 12, 2005 (gmt 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 Jul 12, 2005 (gmt 0)

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


 9:11 pm on Jul 12, 2005 (gmt 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 Jul 12, 2005 (gmt 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.



 9:22 pm on Jul 12, 2005 (gmt 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 Jul 12, 2005 (gmt 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 Jul 12, 2005 (gmt 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 Jul 12, 2005 (gmt 0)

Thanks, thank you very much!


 10:17 pm on Jul 12, 2005 (gmt 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 Jul 12, 2005 (gmt 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 Jul 13, 2005 (gmt 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.



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

Thanks Jim, good point.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved