There are a few common .htaccess 301 redirect rules that are very useful and that I find myself searching for each time I build a website.
What is an .htaccess file?
The .htaccess, or Hypertext Access file, is a configuration text file that controls the directory, as well as any subdirectories, where it is located on an Apache web server. If you use a Linux-based web hosting plan, your web properties likely run on Apache. You may have seen the .htaccess file in certain directories, particularly if you have deployed WordPress, Joomla, Drupal or any other content management web software. The .htaccess file can include specific instructions to the server. This file can configure the server to require a password for the directory where it resides. The .htaccess file can also be configured to automatically redirect users to another index file or site, restrict or allow users based on IP addresses, and disable directory listings. You may never need to edit the .htaccess file, but if you do, you must make sure that the file is named ‘.htaccess’ only, with the period in front and no .txt or .htm file extension.
How do you redirect a single page?
Redirect 301 /pagename.php http://www.domain.com/pagename.html
How do you redirect an entire site or domain to a new one?
Redirect 301 / http://www.domain.com/
How do you redirect an entire site to a sub folder?
Redirect 301 / http://www.domain.com/subfolder/
How do you redirect a sub folder to different website?
Redirect 301 /subfolder http://www.domain.com/