how to mask URL with htaccess?

Tag: .htaccess Author: jiangshanqq Date: 2009-10-06

for example

i type in

www.myportal.com/cars/

no matter what links i navigate to within this site, i want the address bar in my browser to show just www.myportal.com/cars/

UNLESS

www.myportal.com/userpanel. i want the masking to stop when a link pointing to userpanel is clicked.

Other Answer1

This is not possible to do.

You can frame your site at yourportal.com/cars/ for the effect you want, but it's not something you can do with .htaccess.

comments:

You could also do some tricky stuff with cookies, but I'm not sure that would be worth the trouble.
yeah, but I don't know that you'd be able to do it just with .htaccess. Certainly at least have to modify the code of the site a bit.
okay thank you.
musicfreak: That cookies idea is evil :-) And I'm sure it makes the code of the site an adventure to read
yeah, I thought about mentioning it when I made the reply, but I stand by my original answer. The questioner is incapable of doing it, even if I or perhaps some god of rewrite could.

Other Answer2

You can't do this with a .htaccess since by their very definiten URLs have to point to something and that doesn't change. You can't change a singly URL to mean whatever you want in that instant for a single session.

Mind you, it has been done before, it's called spoofing and is usually done for purposes of framing users by displaying a fraud site and showing a real URL in the address bar. Some etchniques might still be out there that work. I'd adivse against it, though.

Disclaimer: It's not me who suggests the following, it's my long-forgotten clone from the early 90s. He doesn't know any better about proper web standards and accessibility. Please refrain from using the following suggestion since it is, in fact, bad. Frames may have some uses on the web. This is not one of them and a pretty stupid thing to do. The accessibility and other drawbacks (loss of deep links) severely outweigh any potential benefits.

You may come closest with a frameset. You have a frameset which is at www.example.com/cars/ and just one frame in it which displays your site. Now every link you click will only change the location of the frame, not the frameset, meaning the URL in the address bar is still the same. You only need to add the target attribute to links that go to www.example.com/userpanel:

<a href="/userpanel" target="_top">Foo</a>

This will cause that URL to replace the old frameset.

You now don't have a way to link directly to a specific page, though.

comments:

i have a concern some sites will try to redirect out of the iframe when its detected.
I didn't suggest an iFrame. Also why are you concerned about 3rd party sites? They shouldn't ever appear in your frameset.