0

Is there any way to mask URLs with PHP or something else? I want to use a custom domain with goo.gl, basically I want to be able to send someone to http://l.bearce.me/iS7tz and have them reidrect to http://goo.gl/iS7tz automatically.

I swear I've seen something like this before, but I can't remember the name of it.

JacobTheDev
  • 17,318
  • 25
  • 95
  • 158
  • I don't understand. You want them to go from your subdomain to google url shortener then back to your homepage? – Jared Aug 14 '12 at 19:05
  • There are are number of way to perform redirects. The most appropriate is probably at the web server level (i.e. Apache mod_rewrite if using Apache). You can use PHP to do this via `header('Location: XXXXX');` calls, but not much sense in using PHP when you can do it without having to invoke PHP at all. – Mike Brant Aug 14 '12 at 19:10

1 Answers1

2

You mean this? (URL cloaking, plain HTML with onclick event)

<a href="http://google.com" onclick="window.location='http://yahoo.com';return false;">Google</a>

Or this? (HTTP redirect)

<?php
// get $path form the url (I suppose you're using mod_rewrite or similar)
$path =  $_GET['some_url_var'];

header("location: http://goo.gl/$path"); // redirect
?>
Peter
  • 5,138
  • 5
  • 29
  • 38
  • Well, I'd be sharing links on things like Facebook, Twitter, etc, so a plain HTML solution won't work. What I'm talking about is when I send someone to a URL on my subdomain, instead of looking at my site, it redirects to the same page on goo.gl. I don't want to have to do any kind of manual configuration of each page, because that kind of defeats the purpose. – JacobTheDev Aug 14 '12 at 19:35
  • Then use the second option: URL-Rewrite to get the $path and HTTP redirect. – Peter Aug 14 '12 at 19:36
  • SO I just put that on my index.php and it should automatically work? – JacobTheDev Aug 14 '12 at 20:28
  • No. You need to configure apache's `mod_rewrite` to parse the URL and convert it into something that php can read, for example: `foo.com/bar` into `www.foo.com/?id=bar`. And then, in PHP you can handle that. If you don't know how to do it, search in google or StackOverflow about URL rewriting. – Peter Aug 15 '12 at 11:18