Web Publishing - Redirects
Working with files on Athena
The Following instructions assume you know how to access and work within your Athena locker. See How can I get started with a web.mit.edu website? for access instructions.
Summary
When you sunset a webpage or website using a HTTP 301 redirect to move traffic to a new location will expeditiously update search engines. It's also valid to redirect traffic to archive content that shouldn't be displayed to current visitors.
The web servers at web.mit.edu and www.mit.edu are heavily customized and provide limited Apache directives. They do not heed configurations in .htaccess but do obey Redirect and RedirectMatch directives in .htaccess.mit.
Where does the .htaccess.mit go?
The .htaccess.mit file needs to be readable to the web server, and in or above the directory it controls in the tree. These are interpreted first at the root of the directory tree, and any unreadable .htaccess.mit file causes an error.
Redirecting an entire locker/website
It's common to shut down a locker/website with a redirect such as:
# Permanently redirecting everything in this locker on 2024/10/10 by jruser RedirectMatch 301 .* http://example.com/
Redirecting single pages or directories
The below examples show how to redirect single locations to locations at a new site. Note that the original page location referenced in your redirect should begin with a / and the name of your locker on {[web.mit.edu}}. So if your old page URL was http://web.mit.edu/old/about.html then your redirect should reference /old/about.html.
The redirect entry in the .htaccess.mit file will have four components in the specified order:
The Redirect directive | Type of redirect | Old location | New location |
Here are several examples of how to use Redirect to redirect specific locations to their new ones.
# Two ways to create a permanent redirect sending visitors # going to web.mit.edu/old/page.html to newsite.mit.edu/page.html Redirect permanent /old/page.html http://newsite.mit.edu/page.html Redirect 301 /old/page.html http://newsite.mit.edu/page.html # Two ways to create a temporary redirect sending visitors # going to web.mit.edu/old/page.html to newsite.mit.edu/page.html Redirect temp /old/page.html http://newsite.mit.edu/page.html Redirect 302 /old/page.html http://newsite.mit.edu/page.html # Two ways to create a "page removed" redirect sending visitors # going to web.mit.edu/one to newsite.mit.edu/ and letting search engines # know that an equivalent page does not exist on the new site Redirect gone /old/page.html http://newsite.mit.edu/ Redirect 410 /old/page.html http://newsite.mit.edu/
Other HTTP result codes are supported as well, but the ebove three are the most commonly used ones for site redirects. Note that Redirect will do a prefix match, so if you do not specify each page fully, this can lead to unpredictable results. For example, this redirect:
# Create a permanent redirect for locations that begin with # web.mit.edu/one Redirect 301 /old/ http://newsite.mit.edu/
will only work if there is an equivalent page for every old page on the new site. It will redirect web.mit.edu/old/index.html to newsite.mit.edu/index.html, web.mit.edu/old/about.html to newsite.mit.edu/about.html, and so on.
Redirecting patterns and matching subsets of pages
The RedirectMatch directive can be used to redirect certain pages and locations based on matched patterns and wildcards. You can redirect many pages at once using pattern matching, or target a specific page. You can also reference portions of the original page name in the destination for your redirect. For example:
# Permanently redirect every page in the "web" directory at web.mit.edu/one # to its matching page on the new site in the "two" directory. For example, # the old page web.mit.edu/one/web/about.html would be redirected to # example.com/two/about.html RedirectMatch 301 ^/one/web/(.*)$ http://example.com/two/$1
The RedirectMatch directive is very powerful and can be used for complex pattern matching and redirects. For more information, see: Apache Group's documentation on RedirectMatch.
![]() | Perl Regular Expressions not supported The mod_alias that runs on web.mit.edu is an older version that doesn't support Perl-Compatible Regular Expressions (PCREs), only POSIX Extended Regular Expressions (EREs). This means it will only provide the level of regular expression support typically available in the egrep command. |
![]() | Don't use meta-refresh The old meta-refresh tag used in page headers is no longer recommended. This tag used to be embedded in the header of HTML pages, but it required the old pages to remain around, and creates more overhead for the visitor as the old page needs to be loaded before the browser is redirected to the new one. If you are still using meta-refresh, we recommend that you use Redirect or RedirectMatch instead. |