Hostwinds Tutorials
Search results for:
Table of Contents
Tags: htaccess
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.
ReplaceWithYourDomain.com Should be replaced with your domain name in the below examples
# 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/
# Redirect the index page to a subdirectory:
Redirect /index.html http://ReplaceWithYourDomain.com/subdirectory/
# Redirect from an old sub-directory or file to a new sub-directory or file:
Redirect /OldSubdirectory/OldFile.html http://ReplaceWithYourDomain.com/NewSubdirectory/NewFile.html
# Define an alternate index file:
DirectoryIndex mynewindex.html
# 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]
# Hide contents of a directory if index file does not exist
Options -Indexes
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