Hostwinds Tutorials

Search results for:

Table of Contents

Simple Redirects:
More Advanced Options:
For WordPress users:

How To Edit A .htaccess File

Tags: htaccess 

Simple Redirects:
More Advanced Options:
For WordPress users:

Please note that editing .htaccess files is very unforgiving. Even the slightest mistake can cause your site to display content incorrectly or not at all.

When editing your .htaccess file, always make a backup copy so you can get back to a working configuration if something goes wrong.

Linux systems are case sensitive, even the URL.

If you have trouble uploading the file, you may have to name it htaccess.txt and then rename it once it's on the server. Should be replaced with your domain name in the below examples

Simple Redirects:

# Permanent Redirect:
Redirect 301 /
# Temporary Redirect (Use this if you plan to move back to the original site to save your SEO scores):
Redirect 302 /
# Redirect the index page to a subdirectory:
Redirect /index.html
# Redirect from an old sub-directory or file to a new sub-directory or file:
Redirect /OldSubdirectory/OldFile.html
# Define an alternate index file:
DirectoryIndex mynewindex.html

More Advanced Options:

# Redirect to
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Redirect to
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]
# Redirect an open connection to your secure SSL connection:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R,L]
# Hide contents of a directory if index file does not exist
Options -Indexes

For WordPress users:

If your site stops working, the .htaccess file is the first place you should check.

Rename the .htaccess file to .htaccess_bak and then browse to your site.

This works a lot of the time.

If renaming the .htaccess file fixes your site, you can then place the following standard WordPress .htaccess configuration into a new .htaccess file.

Here are the contents of the default WordPress .htaccess file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]  
# END WordPress

Written by Hostwinds Team  /  August 21, 2017