How to Edit a .htaccess File

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.


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 topics:

Redirect to

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Redirect to

RewriteEngine On
RewriteCond %{HTTP_HOST} !^ReplaceWithYourDomain\.com$ [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]

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 standard 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


Leave a Reply