-1

i want to show different url in the address bar rather than actual url.

i am using this example

function init() {
  document.getElementById("test").onclick = function(e) {
    jx("counter.php?url=" + escape("http://www.google.com/")); //Use your favorite ajax library here.
  }
}

window.onload = init;
<a href="http://www.google.com/" id="test">Go To Google</a>

my counter.php is like this

<?php
  header("Location: " . $_GET['http://www.hotmail.com']);
?>
ADyson
  • 57,178
  • 14
  • 51
  • 63
Sarah_Salar
  • 183
  • 2
  • 13
  • 1
    You can't - the address bar is the browser's code - you change it by going to a different page. – Jack Bashford May 07 '19 at 08:28
  • 2
    What exactly is your Problem? – FMK May 07 '19 at 08:28
  • In your PHP code, use `header("Location: " . $_GET['redirect_to']);` –  May 07 '19 at 08:30
  • is it possible to falsify the url to hide the target url – Sarah_Salar May 07 '19 at 08:30
  • i want to hide my actual domain url – Sarah_Salar May 07 '19 at 08:31
  • Aren't you already doing that? Edit: how is that supposed to work? They have to visit your site in order to see it. –  May 07 '19 at 08:31
  • 1
    No, you can't do that. Thankfully. – BenM May 07 '19 at 08:32
  • http://www.openjs.com/articles/ajax/target_url_hiding.php i am using this example – Sarah_Salar May 07 '19 at 08:34
  • this example shows we can hide our target url – Sarah_Salar May 07 '19 at 08:36
  • 1
    What is the problem that you are having with the code that you have posted? – Turnip May 07 '19 at 08:39
  • i wanted to go to hotmail website but url will be showing google – Sarah_Salar May 07 '19 at 08:42
  • this code take to google page with same google url] – Sarah_Salar May 07 '19 at 08:42
  • Possible duplicate of [change URL link with javascript without refresh](https://stackoverflow.com/questions/10261393/change-url-link-with-javascript-without-refresh) – Carlos Alves Jorge May 07 '19 at 09:02
  • 1
    Why would you ever want to do this? Are you trying to fool the user? What would be the purpose of that, other than some kind of fraud attempt? Showing the user a different URL than the one being displayed in the bar is an abuse of the trust between the user and the site they are visiting. Thankfully it's not really possible to do this. – ADyson May 07 '19 at 10:07
  • hold your far fetched assumption to your self. some site needs security. – Sarah_Salar May 07 '19 at 10:11
  • 1
    @Sarah_Salar — Lying about your URL doesn't provide security. – Quentin May 07 '19 at 10:13
  • it is not lying if u do not understand my problem then kindly be quite. – Sarah_Salar May 07 '19 at 10:14
  • 1
    If your reason is not malicious, then to me this sounds like some attempt at "security by obscurity"...which as is well known, is not really security at all. Can you kindly explain exactly why you want to do this? What kind of security are you trying to achieve? What problem are you trying to guard against? If we can understand your motivation, then we might be able to tell you a sensible way to achieve it. Thanks. – ADyson May 07 '19 at 12:37

1 Answers1

3

I want to show different url in the address bar rather than actual url.

In general: You can't.


The History API allows you to manipulate the history to show different URLs without changing page … but only within the same origin. (So you could be on http://example.com/ but show http://example.com/other but not http://example.net/).

This is intended so that heavily Ajaxy websites can have real URLs for different "pages" while generating the pages client-side. The intention is that the same pages can be generated server-side when the URL is visited directly or by a client which doesn't support JavaScript. This allows for search engine friendly, accessible content, with a performance boost while navigating from page to page within the site when the client allows it.


It is possible for one URL to serve the same content as another URL. This could be a simple static copy, or it could be pulled dynamically with server-side code (or Ajax if the CORS policy allows it).

Of course, all relative URLs would need to be updated when the content is copied otherwise they will just break.

Naturally, you couldn't use this to make http://www.google.com/ display the same content as http://www.hotmail.com: You don't control http://www.google.com so cannot change the content it serves.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335