Forum Moderators: phranque

Message Too Old, No Replies

trying to hide dynamic php url

hide dynamic php url

         

khakiman

7:43 am on Sep 13, 2007 (gmt 0)

10+ Year Member



hi all. I'm trying to use .htaccess to hide a url in the address bar.

what i have is www.site.com/cart/cart.php
what i want to show up is www.site.com.

however i don't want to redirect from www.site.com/cart/cart.php to www.site.com I just want it to appear that way to the end user.

Can anyone help? thanks.

mp3mechanical

10:23 am on Sep 13, 2007 (gmt 0)

10+ Year Member



you can use old , simple & stupid way of using frames (either normal frame or iframe).

and if you want any other option u can give a try to mod_rewrite

jdMorgan

2:07 pm on Sep 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is no "magic" solution to the problem as-stated. The link you publish on your pages is what "shows up" in the browser address bar; This is an immutable law of HTTP, and only an external redirect can change it (and only after the fact).

The usual technique involves three steps:
1) Change the URLs in the links on your pages to the form you want displayed in the browser.
2) Internally rewrite those URLs, when received in requests by your server, to the form needed to locate and serve the appropriate content.
3) Externally redirect the "unwanted-format" URLs to the form you want displayed in browsers and indexed by search engines (optional).

PHP's preg_replace is particularly useful for the first step, unless you find it easier to update your database.

mod_rewrite can be used to do the internal rewrites for step two and the external redirects for step three.

The third step is a bit tricky, since you must test the server variable %{THE_REQUEST} and redirect only direct client requests for the "unwanted" URLs; Otherwise, step two and three together will create an 'infinite' rewrite/redirect loop.

Note that a successful implementation of this method requires that both forms of the URL contain all of the information needed to derive/create the other form.

Jim

khakiman

7:37 pm on Sep 13, 2007 (gmt 0)

10+ Year Member



thanks guys you are quite helpful