|
Home »
Web
»
Web Site Management
Summary: It's sometimes the case that you'll want one URL to automatically forward to another. We'll look at several approaches to redirecting URLs.
This is one of those things that I do just infrequently enough that I can never remember the exact syntax, and I end up looking it up again from the last time I did it. Fortunately there are a couple of ways, depending on what kind of access you have to your domain and/or server, and what kind of functionality your domain registrar or DNS provider gives you. • 1. Registration Only; No Server If all you've done is register the domain, but have not actually provided for a web server to serve up pages from that domain, you'll be relying on the DNS functionality that your registrar has provided. DNS is normally where you tell the world "this domain is at that IP address" (using an A record). Without a server there is no IP address, so you need to do something different. One common approach is to create a CNAME record. It's similar to an A record except that it says, in effect, "this domain is really that domain". The "catch" if you want to call it that, is that the web server that will eventually serve up pages for this domain must know about it. For example: "ask-leo.net" has a CNAME record to say that it's really "ask-leo.com". That at least gets it to my web server. I then had to configure my web server to handle requests for "ask-leo.net". I happened to configure it to redirect those requests to "ask-leo.com". (See the URL Rewrite discussion at the end of this article for just how that was done.) "Exactly how that's done will vary based on which DNS
provider you happen to be using, which features they happen to expose and
how."
Another approach, depending on the features your registrar or DNS provider gives you, is called a "url redirect". That allows you to specify something much like "this domain should redirect to that page". This is also very powerful in a couple of different ways. Without any server-side work, "askleo.info" redirects to "ask-leo.com". All it took was a URL redirect in my registrar's DNS control panel. Perhaps more interesting is "newsletter.ask-leo.com" which uses a URL redirect to send you instead to "ask-leo.com/newsletterinfo.html". This actually relies on features supplied by your DNS provider or registrar, so you'll need to check for availability. All of the steps above involve dealing with your DNS provider. I say "DNS provider or registrar" above because most registrars provide DNS functionality as part of their service these days. What I can't tell you are the specific steps you need to step through to set an "A" record, create a "CNAME" record, or create a "URL redirect". Exactly how that's done will vary based on which DNS provider you happen to be using, which features they happen to expose and how. Server With Only ".html" Access If the domain you want to redirect is already pointing at a server on which you can place ".html" files, there's another technique that doesn't require any DNS work at all. It uses HTML to perform the redirection automatically. The technique is typically referred to as a "meta refresh", and is the one who's syntax I keep forgetting. Here's the entire contents of the page "http://ask-leo.com/currentnewsletter.html":
<html>
<head>
<title>Ask Leo! - Leo's Answers Latest Newsletter</title>
<meta http-equiv="refresh" content="0;url=http://ask-leo.com/leos_answers_82_june_15_2007.html">
</head>
<body>
<p>
Redirecting to latest newsletter. If you're not redirected within a couple of seconds,
click here:<br />
<a href="http://ask-leo.com/leos_answers_82_june_15_2007.html">Leo's Answers #82 - June 15, 2007</a>
</p>
</body>
</html>
The line of interest is the fourth line that begins with "<meta". The operation is "refresh" which means to "refresh" the current page with the information that follows. The content begins with a zero, which is the number of seconds to wait, and then the URL that you should be taken to. Thus when you visit http://ask-leo.com/currentnewsletter.html you'll be immediately redirected to the page containing the current newsletter. Most of you will, but not all. Meta-refresh can be disabled by the user so the alternate, manual approach is still required. That's why it's important to include the text in the actual page instructing people to "click here if you're not automatically redirected". In your case I'd put on your domain.dk home page a meta refresh of the form: <meta http-equiv="refresh" content="0;url=http://domain.com"> Servers With URL Rewriting I'm expecting that the prior methods will be appropriate for 99% of the people who might be interested in the topic. But I feel I have to include this technique for the 1% group - the group that I'm actually in, since this is what I do for most of my sites. If you have an Apache web server, or another server that supports the same functionality, and it's configured to allow URL Rewriting in .htaccess files or you have access to the configuration files for the web server, then you can do redirection a slightly different way. First, you would simply point your domain to your web server as if you were actually hosting it there. In your case, you'd go ahead and point your ".dk" domain with an "A" record to your web server. Then, you would configure your web server to actually host that domain. Finally, either in the configuration files for that site on your web server, or in the .htaccess file in the root of where the pages for "domain.dk" would reside, you would place the following: RedirectPermanent / "http://domain.com/" That'll send all the requests to the redirected target. (I realize that statement is technically not URL rewriting, but it's close enough for this discussion. Full URL Rewriting is incredibly powerful and complex and well beyond the scope of this answer.) Related: Article 11608 | Posted June 21, 2007 |
Popular & Hot How do I make a new MSN Hotmail account? How do I delete history items from my Google tool bar? My desktop Recycle Bin has disappeared - why, and how do I get it back? How do I delete my Hotmail account? I accidentally deleted my Recycle Bin in Vista - how do I get it back? New & Important How can I get the old Windows Live Hotmail back? Internet Safety: How do I keep my computer safe on the internet? Are free email services worth it? Would you please recover my password? My account has been hacked or I've forgotten it.
Stay Informed Archives Advertisers |
|
•
.dk works exactly like .co.nr (except with advertisements).
Say you wanted site.dk to display freewebs.com/site, then you configure site.dk to show freewebs.com/site (in a similar way to using CNAME i believe), however, site.dk will show freewebs.com/site as a frame, and the URL in the address bar will stay the same as long as you click links that dont open a new webbrowser.
My advice for the person who asked this is to rent a cheap server.
If you cant find one, i highly recommend precision-media.net and go with their $10 plan.
Good luck on your site, and leo: I Know where to come when im stuck on HTML coding now ;) thanks mate.
Posted by: JaiiBee at October 4, 2007 4:09 PMI know how to redirect to a webpage but what I want is to redirect to a totally different webpage if Primary Redirected page is down. So if PAGE_A is being Redirected to PAGE_B but if PAGE_B is down it should redirect somehow to PAGE_C. Is it possible?
Posted by: Mahmood at February 11, 2008 1:12 PMMahmood, yes it's possible. That's called Load Balancing...
Posted by: Tom Brown at February 13, 2008 9:03 AMIs it possible within a table cell on one web page to show the contents of another web page?
Posted by: Barbara at March 19, 2008 6:13 AMYes, thats called an iframe.
Posted by: Harry Rickards at May 19, 2008 9:26 AMHarry Rickards (h-rickards.co.uk)
Hi, I know how to use the Meta refresh. I've used it on my website to forward everyone to a diferent website.It's nic because it keeps my original domain name in the web browser. crossroadskenner.com does a meta refresh to http://www.onestopwebonline.com/crossroads/. Unfortunately, if one of the pages on the onestopweb site is longer then the page on crossroadskenner.com, then the page is cut off at the bottom. Also there is a white border around the page. I can make my page size larger on crossroadskenner.com however that makes every page long even if the page on the other site doesn't have anything on it. Is there a simple way around this?
I'm a novice at this and am not sure about the A record and cname stuff.
My domain is hosted through offivelive.com. I happened to get in when they were Betatesting officelive.com and gor my domain and web site free. I could move the domain, but then I would have to start paying a fee to maintain the domain name every year, where Microsoft is currently maintaining the fees. If I change the domain name then I will have to start paying for it. So I'd like to maintain my domain where it's at and forward to a different page. Officelive dosen't offer some of the features that onestopweb offers which I like.
Rob
Posted by: Rob at October 3, 2008 11:51 AMWhat about cases that I need to get some data in the response from the remote server?
Case of client requesting server1 and him, in turn, request server2 for the data (that needs to go back to the client).
Thanks.
Posted by: Amir at October 12, 2008 4:00 AM