Portal Home > Knowledgebase > Web Hosting > Shared Hosting > Troubleshooting > htaccess Editing and How To

htaccess Editing and How To

.htaccess Editing and How To

Before you begin:

Please note that editing .htaccess files is very unforgiving. Even the slightest mistake can cause it 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 / http://ReplaceWithYourDomain.com/

Temporary Redirect. Use this if you plan to move back to the original site to save your SEO scores

Redirect 302 / http://ReplaceWithYourDomain..com/

Send index to a subdirectory.

Redirect /index.html http://ReplaceWithYourDomain.com/subdirectory/

Send from an old subdirectory / file to a new subdirectory / file

Redirect /OldSubdirectory/OldFile.html http://ReplaceWithYourDomain.com/NewSubdirectory/NewFile.html

Define a different index file

DirectoryIndex mynewindex.html


More advanced topics:

Redirect YourDomain.com to www.YourDomain.com

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

Redirect www.YourDomain.com to YourDomain.com

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

Redirect an open connection to your secure SSL connection

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.ReplaceWithYourDomain.com/$1 [R,L]

For Wordpress users.

If you 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 much 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


Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read