Situation

So my friend Josh and I have been building a website and online presence for the program we teach in (The PLTW Biomedical Sciences Program at Bel Air High School) for a few years. We were tasked this summer to do the same thing for the whole school. Because of URL availability, we decided to brand Bel Air High School as myBAHS.

I’ll write more about the overall process later, but today I am going to share a basic trick to make free branded links to any online resource using something called .htaccess.

Problem

We wanted to make a few standard social accounts under the myBAHS brand so we decided on Twitter, YouTube, and Flickr.

With varying success, we were able to jump through hoops to get custom URLs for the various sites, but we wanted a simpler and more streamlined way to share our profiles through signs and verbal communication.

We decided to investigate URL redirects as a solution.

Solution

After reaching out to our hosting provider Dreamhost (who is awesome) we got the advice to look into .htaccess redirects.

When I looked into this, it seemed like this type of thing was considered child’s play in web developer world so most of the information/directions I found actually had a few gaps. Eventually, I assimilated enough information to fill those gaps, so here is what I synthesized from all the different sources.

How To Create a 301 Redirect Using a .htaccess File

  1. I used my FTP client Transmit to connect to my server.
  2. Once connected, I entered the folder for my domain.
  3. Then I created folders in this folder for each link I wanted to create.
    1. This was a touch confusing and the name of the folders I created ended up being the “page” portion of my URL, i.e., mybahs.com/youtube.
    2. See our 4 redirects here:
  4. Inside of each folder, I created a file called .htaccess 
  5. I only needed one line of code in each of these files. Here is the code for our YouTube link:
    Redirect 301 /youtube/ https://www.youtube.com/channel/UCz7JabRVcO06gPkahqKyBUQ
    1.  The first portion is the command. Redirect 301 tells the machine that it is going to be swapping out the URL of the middle portion and replacing it with the URL found in the last portion.
    2. The spacing in between each section matters (it is one space, but it needs to be there)
  6. I made sure to save this file correctly
    1. Only one .htaccess file per folder
    2. The correct .htaccess file is in the correct folder.

Result

We now have a way to easily create “clean,” branded, and custom links to any resource we need to.

The four we have right now are:

This is great for consistency and also for dealing with errors if someone types in the wrong address, they are still landing on our website!

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.