Redirection: How to redirect a page or directory using an .htaccess file

Summary

If a user visits https://www.mysite.com/index.html she will be redirected to a page in a new location https://www.mysite.com/mydir/index.html .

The 301 signals to the browser that this is a permanent redirect by sending a “301 Moved Permanently” status code. If the user happens to visits the old URL, the browser will automatically redirect to the new URL This technique should not impact SEO.

Body

This article contains information for users who want to redirect an outdated web page / directory to current, relevant content. These steps will work on Copland hosted sites. This CANNOT be used on CampusPress WordPress sites.

Redirect from a directory to a file

This .htaccess file is placed within the old directory.

RedirectMatch 301 "^/olddir(/.*)?$" "https://www.udel.edu/newdir/"

 

Redirect from a file to a directory

This .htaccess file is placed within the old directory where the file is located.

Redirect 301 page.html "https://www.udel.edu/dir/"

 

Redirect an old directory to a new directory

This redirects an old directory (/old_dir) to a new directory (/new_dir). This .htaccess file is placed within the old directory.

Redirect 301 /old_dir "/new_dir"
 

Redirect a file to another file in another directory

This redirects a file (index.html) to a new file in a new directory (/mydir/index.html). This .htaccess file is placed within the old directory.

Redirect 301 /index.html "/mydir/index.html"

 

RewriteEngine directives restrictions and security

Due to security risks +FollowSymLinks is disabled on Copland. This also prevents the use of the RewriteEngine directive. Use the redirect techniques above to get around this.

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^old_dir/(.*)$ /new_dir/$1 [R=301,NC,L]

Details

Details

Article ID: 510
Created
Thu 8/1/19 8:43 AM
Modified
Fri 3/4/22 9:59 AM