.htaccess for redirects

Page address: http://www.mnsu.edu/its/web/resources/htaccess.html

... > Resources > htaccess

Before we get started.... .htaccess files can be tricky. They can cause all of the folders below them to go wacko. Be careful when you're editing these. Make backups of the file if you are editing an existing file.

If you do make a redirect you must tell Aleksey, lazar@mnsu.edu. We're trying to keep track of these so we can eliminate them from our site in the future (after enough time has passed.)

.htaccess redirects

  • All of the statements go into an .htaccess file in the directory in question. If there isn't a directory there, because it moved, it must be created.
  • You only need one "RewriteEngine on" per .htaccess file.
  • If there is already something in the .htaccess file append your new info. to the bottom of the file.

Redirecting the index file

Note: destination can be full or root relative

RewriteEngine on
RewriteRule ^$ /its/ [L,R=permanent]
RewriteRule ^index.html$ /its/ [L,R=permanent]

Single document direct

Note: destination should be full or root relative

RewriteEngine on RewriteRule ^olddoc.html$ /its/newdoc.html [L,R=permanent]

Redirect everything and sub-directories to a single destination

Note: destination should be full or root relative

RewriteEngine on
RewriteRule ^.*$ /its/ [L,R=permanent]

Seamless redirect from an old directory to a new location

Note: destination should be full or root relative

RewriteEngine on
RewriteRule .*/other /its/data/ [L,R=permanent]
RewriteRule (.*)$ /its/data/$1 [L,R=permanent]