0

Here is my problem:

I want to hide the parameters in url, so any page only can display www.website.com

I added a frameset for the index.php page,

it's perfect when user click any link in this page,

but if user open a link by right click -> open in new tab or window,

the whole URL with parameters will be shown,

any idea to prevent when user open a page in frameset by open in new tab?

Zhang Zhenyun
  • 23
  • 1
  • 4
  • Use .htaccess: [mod rewrite to hide url](http://stackoverflow.com/questions/10720145/mod-rewrite-to-hide-url) – Antony Jan 29 '13 at 04:18

2 Answers2

1

Generally to accomplish this you need to set up the server to act in this way. It's generally refered to as URI's, or "Pretty URI's". This is also a key component in designing your app in RESTful senses.

If you have access to your servers configuration and are running a LAMP stack you can accomplish this with .htaccess files. But you will still need your server-side script to handle the rest of the requests.

Here's an example .htaccess file that will remove the extension and query:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php /$1 [R=301,L]

But you should refer to RESTful anyways if you definatly want precise URI's http://phpmaster.com/rest-can-you-do-more-than-spell-it-1/

And another tutorial on .htaccess and "Pretty URLs" http://net.tutsplus.com/tutorials/other/using-htaccess-files-for-pretty-urls/

CP510
  • 2,297
  • 15
  • 15
  • thx, but do I need to change any script in this query? my server is IIS 7, I create a htaccess file with this query, and import to IIS 7, but still display the parameters – Zhang Zhenyun Jan 29 '13 at 06:07
  • IIS 7 doesn't support apache's .htaccess files. Heres an article on converting them though. http://www.iis.net/learn/extensions/url-rewrite-module/importing-apache-modrewrite-rules But given I don't know IIS I couldn't really help any more. – CP510 Jan 29 '13 at 06:14
0

Well, hiding URLs like this is generally not a good idea, but you could try this:

<a href="somepage.php" onclick="location.href=this.href;return false;">Link</a>

You can also use some simple JavaScript so you don't have to manually add the event handler to each link:

document.body.addEventListener("click",function(e) {
    var t = e.srcElement || e.target;
    if( !t.tagName) t = t.parentNode;
    if( t.tagName.toLowerCase() == "a") {
        location.href = t.href;
        return false;
    }
},false);
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592