The University of Vermont

UVM WEB GUIDE: General Web Topics and Tools

Creating a Simple URL with a Redirect

Most departmental websites at UVM are eligible for a single simple tilde-less web address. Usually this adress is simply the tidle address without the tilde but a more intuitive name may be chosen in lieau of the tilde-less option. This address is not created automatically, requests must be made to the web team and are only granted to official UVM websites. Any name requests that are not indicative of the sites that they represent, may not be granted. (Personal websites are not eligible for tilde-less addresses.)

You may also be interested in creating in shorter URLs for pages within your website. Reasons for this might include:

  • you wish to publish the address of a specific page in your website on some print materials
  • you regularly need to direct people on the telephone to a specific page on your website that you don't wish to make publically available via your homepage
  • you need to include a very long address in an email and you don't want it to wrap onto two or more lines (and possibly break the link)

In these cases, you can create your own "more friendly" addresses using a tilde or tilde-less address. Additionally, you may use these methods when moving or merging websites.

.htaccess

This is the recommended and simplest method for redirects. In this server-based method, you will create a text file and save it to your public_html directory. The filename is: .htaccess. It is important to note that because the filename starts with a "." that you may need to change the settings on your file transfer program to see this file in your directory listings.

There are two basic types of redirects: 301 is a permanent redirect, and 302 is a temporary one. The structure of the file is quite simple, as you can see in the following example. Note, that you can only create redirects for web addresses within your website but they can point to addresses anywhere, even outside of UVM.

 Redirect 301 /~mydept/calendar/ http://www.uvm.edu/~mydept/?Page=currcalendar.html&SM=calmenu.html
 Redirect 302 /~mydept/blog/ http://adms.blog.uvm.edu/2008/05/summer_is_coming_are_you.html
 

In the previous example, www.uvm.edu/~mydept/calendar would now go to the longer more unfriendly address. And, if this department had a tilde-less address, www.uvm.edu/mydept/calendar would go there too!

HTTP meta refresh

This is the most manual method available and requires no server services. If you are moving your website to UVM from a hosted service or server with limited services, this might be a good choice. The following code can be used in an index.html page at the root of your site (for a homepage redirect) and/or any individual pages which you wish to redirect to a new location.

 <html>
 <head>
 <meta http-equiv="Refresh"content="0; url=http://www.uvm.edu/~mydept/">
 </head>
 <body>
 <p>Our website has moved. Please visit <a href="http://www.uvm.edu/~mydept/">our new website</a>!</p>
 </body>
 </html>
 

PHP redirect

Ok, if you are on zoo, you can use php to make your redirects too. Since index.php will control the root of any web directory, the index.php file is the most powerful place to control redirects. For example the following code located in a directory "calendar" would work similar to the first .htaccess listed previously. You can also use this method to redirect any php page.

 <?php
 Header("HTTP/1.1 301 Moved Permanently");
 Header("Location:http://www.uvm.edu/~mydept/?Page=currcalendar.html&SM=calmenu.html");
 ?>
 

Last modified November 14 2008 01:02 PM

Contact UVM © 2009 The University of Vermont - Burlington, VT 05405 - (802) 656-3131