How Short URL works? - short-url

I'm thinking of implementing a short/friendly URL system in my company.
I've read a lot of articles describing how to do it. I understand the process but I still have some questions: we have server A and client B. Server A has all the logic for URL rewriting and redirecting. But how can Client B, external to that server but in the same domain, know what is the hostname or IP for http://server.A/theURL? If the name of "server.A" is not known for the client it'll return an "unknown host" error. How can you "publish" that short url "domain" in the network? I don't think you have to modify the .hostname files of every single PC...
Thanks,

The way I did it was to point the vanity domain url to goo.gl. Then request a url from goo.gl shortener using my google API key then I str_replace the url with my vanity url and output that as the final solution.

Consider using (free) APIs from major url shortening services:
BITLY https://dev.bitly.com (most known)
CLICKMETER http://clickmeter.com/api (best analytics)
GOO.GL https://developers.google.com/url-shortener (simple)
OWLY (integrated with HootSuite)
REBRANDLY https://developers.rebrandly.com (use your domain name)
SHORTE.ST https://shorte.st/howitworks (monetize clicks)

Related

Building URLs in Go including server scheme

I am creating a REST API in Go, and I want to build URLs to other resources in my replies.
Based on the http.Response I can get the Host and URL.
However, how would I go about getting the transport scheme used by the server? http or https?
I attemped to check if server.TLSConfig is nil and then assuming it is using http since it says this in the documentation for http.Server:
TLSConfig *tls.Config // optional TLS config, used by ListenAndServeTLS
But it turns out this exists even when I do not run the server with ListenAndServeTLS.
Or is this way of building my URLs the wrong way of doing things? Is there some other normal way of doing this?
My preferred solution when running http and https is just to run a simple listener on :80 that redirects all traffic to https. Then any real traffic can be assumed to be https.
Alternately I believe you can access a request's URL at req.URL.Scheme to see the protocol.
Or do you mean for the entire application? If you accept configuration to switch between http and https, then can't you look at that and see which they chose? I guess I'm missing some context maybe.
It is also common practice for apps to take a baseURL via flag or config to generate external urls with.

Multiple http request in one request to different domain

May be this is an awkward question due to my lack of knowledge and I don't know which topic I should search to know about this, but I kind of hope/wish there was a solution.
What I mean is there any way I could send http requests to multiple domains ?
For eg: If I send an http request for a page www.facebook.com/stackoverflow.
I want a simple info that this link is clicked by someone by sending a message to my domain also.The URL can be changed to anything with primary URL still as main source.
What I mean plainly is
www.facebook.com/stackoverflow+{additional code to some way a request to my website also }
When you send a request for http://www.facebook.com/stackoverflow, it requires making a TCP connection to www.facebook.com's server and then sending an HTTP request for the /stackoverflow resource on that server. You can't make Facebook forward the same request to another server.
If you want the link to request your domain, you have to declare your domain as the target of the link. You can specify another URL as an extra parameter, so your domain can use an HTTP redirect to forward the client to that URL when ready. For instance, search engines do this all the time to track the links that users click on in search results.
For example:
http://www.example.com/doSomething?goto=http%3A%2F%2Fwww.facebook.com%2Fstackoverflow
The client would connect to the www.example.com server and send a request for /doSomething?goto=http%3A%2F%2Fwww.facebook.com%2Fstackoverflow. A script located at /doSomething can do whatever it needs to do, and then redirect the client to the URL in the goto parameter (http://www.facebook.com/stackoverflow).

Get referring domain from HTML5 Audio Tag Streaming URL

Part of a site I am working on at the moment requires Audio/Video previews.
These are server from a different server to the main site.
The Streaming URL is of the form:
www.myserver.com/Preview.aspx?e=I_AM_AN_ENCRYPTED_KEY
The Key is generated by the server that hosts the file, not the site on which the previews are actually displayed. It's kind of an API.
Part of the security to stop these previews being played anywhere except this website is supposed to check the domain which is requesting this, but it seems that HttpContext.Current.Request.UrlReferrer is NULL when requested from an HTML5 video/audio element.
Without posting the domain along with the Key to the API, is there any way that I can get the referring URL on the receiving server, server side?
EDIT:
To clarify:
There is a website with HTML5 elements which are directed to a URL on a different server, the URL and key is provided by this server (not the website)
When the API server receives a request to stream the preview it checks the Key (which basically tells it what to play) and also checks for the referring domain against a list of allowed domains.
Figured it out - in case anyone cares...
Simply replace:
ReferringDomain = HttpContext.Current.Request.UrlReferrer
with :
ReferringDomain = HttpContext.Current.Request.Headers("Referer")
Sorted! :)

Http how to identify redirect from local or remote

how to identify a request( by http redirect ) is from local site or other sites?
such as, i have a site: www.my.com
and www.my.com/a.html will redirect to www.my.com/b.html
other sites will redirect to www.my.com/b.html
how can i identify where the redirect from?
HTTP Referrer may be unbelievable
Server-side you could track IP addresses and match these across requests.
But personally I'd go for the simpler Referrer solution.
See HTTP Referrer Gotchas? for further discussion on this.
Another option you have if you're using dynamic content generation (eg ASP, PHP, etc) is to use URL rewriting rather than redirecting via the client. In this case, the client still thinks they're requesting www.my.com/a but you return the content for www.my.com/b
In the code which generates b you can see that the request is for www.my.com/a so you know that they've been "rewritten".

Creating subdomain in URL alaising

I am creating a social networking site and one of the requirements is to have the subdomain like URL for each user. For example, for the user1 his profile page will be user1.mysitename.com and for the user2 profile page will be user2.mysitename.com.
Can it be done using url aliasing? basically user1.mysitename.com should be www.mysitename.com/profile.aspx?username=user1
I will be hosting this in windows 2003 (IIS6), any help is highly appreciated.
You can either respond to each GET request of user1.mysitename.com with the same contents as www.mysitename.com/profile.aspx?username=user1 or you can answer using a redirection (HTTP 302 response) from the first url to the second url.
However, you have to first make sure the DNS server who is authoritative on mysitename.com is aware to all these domains and respond with the answer you need (either the IP of the server, or a CNAME to a domain that is linked to an IP).
EDIT:
When someone will try to surf to user1.mysitename.com he will first try to resolve user1.mysitename.com to get it's IP - here you need someone to let him know what is the IP of the domain user1.mysitename.com.
After the user has the IP of the domain, he will request the page using HTTP GET request. You need to respond to it somehow. One way is to redirect him to a different URL (www.mysitename.com/profile.aspx?username=user1). Another way is to simply respond to the GET request and give him the page he's looking for.

Resources