Forum Moderators: phranque

Message Too Old, No Replies

Address bar show old url when redirect to new url? Is that possible?

Thanks for helping me on this question.

         

fufu

5:28 am on Jun 18, 2005 (gmt 0)

10+ Year Member



I am a newbie about Apache, so please donot laugh if this question is too simple.

My question is:
when user request a url like:
example.com/keyword
I redirect his request to my real html file
example.com/keyword/keyword1.htm,

But I wish the address bar is still showing his url request. in another world, keep short url,
so easy to remember.

One similar application like:
http://example.com/tag/web
very neat url to remember.

anyway, any guru know an answer to this?
thanks so much!

[edited by: jdMorgan at 5:48 am (utc) on June 18, 2005]
[edit reason] Example.com [/edit]

jdMorgan

5:56 am on Jun 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



fufu,

Welcome to WebmasterWorld!

The technically-correct answer to your question is "No, it is not possible to do a redirect and keep the original URL in the address bar." This is because a redirect, by definition, involves telling the browser to ask for the requested resource at a different URL. So the browser updates its address bar and uses the new URL.

However, there are two ways to avoid the URL update. The simplest can be used if the content is on the same server: Use a rewrite, not a redirect. An internal rewrite simply serves content from a local file-path that is different from the requested local URL-path.

The second method must be used if the content is on a different server. This involves setting up the first server as a proxy for another server. All incoming requests then pass through the first server, and content is returned from the second server, back through the first, and on to the requesting client.

I suspect that all you need to do is to use the rewrite method, as this is most common.

Jim

fufu

6:25 am on Jun 18, 2005 (gmt 0)

10+ Year Member



Jim,

thanks for your quick reply. I tried and seems working now. so happy. :) The following is what I did. You have a good weekend.

----
.htaccess

RewriteEngine on

RewriteRule ^keyword$ http://example.com/keyword/keyword1.htm
RewriteRule ^keyword/$ http://example.com/keyword/keyword1.htm

jdMorgan

3:18 pm on Jun 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The proper rewrite form should be:

RewriteRule ^keyword/?$ /keyword/keyword1.htm [L]

The "?" following the slash makes it optional. Therefore, this one rule should work with both "keyword" and "keyword/".

Jim