htaccess Sign PostEven when a site is otherwise optimized, failing to have a properly configured .htaccess file is a mistake you can’t afford to make. Use this guide as a checklist to avoid neglecting the core of your site.
Disclaimer…
* If you are able to configure your “httpd main server config file,” use that instead.
* This is only for sites using Apache.
* Certain CMS and E-Commerce platforms may allow these settings to be edited through the administration panel instead.

Some servers may not have “mod_rewrite” enabled by default. Add the following line to your site’s root .htaccess file one time to ensure mod_rewrite is enabled:

RewriteEngine On

Depending on your server configuration, you may or may not need the following line after “RewriteEngine on”:

Options +FollowSymLinks

Redirect non-www to www (or Vice Versa)

In a perfect world, choosing the www or non-www version of a domain and setting up a permanent redirect is something done during a site’s infancy. In reality, this just isn’t happening with a large number of websites.
Redirect non-www to www

RewriteEngine On
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]

Replace yoursite.com with your domain!
Redirect www to non-www

RewriteEngine On
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]

Replace yoursite.com with your domain!
How it impacts SEO
Aside from duplicate content, not deciding on a primary URL structure lowers domain authority, dilutes link-building efforts and sends mixed signals to search engines about which version of a page you want indexed. Why distribute incoming link juice to two technically different URLs when you can send it all to one?
Note that for those of you using WordPress or various CMS/E-Commerce platforms, these settings are often taken care of by default or configured through the administration panel.

Redirect Old URLs to New URLs

As a site grows, ages and develops, there are pages that will inevitably become outdated or irrelevant. Other times, you may wish to condense two or three similar pages into one. A 301 redirect is the answer.
Redirect an old page to a new page

Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html

Replace yoursite.com with your domain!
Redirect several pages to one

Redirect 301 /seattle-companies.html http://www.yoursite.com/seattle-company.html
Redirect 301 /seattle-locations.html http://www.yoursite.com/seattle-company.html

Replace yoursite.com with your domain!
How it impacts SEO
301 redirects are a great way to preserve traffic and some of your pagerank. 301 redirects also provide visitors with actual content instead of a 404 error page or something no longer relevant.
Another great use for 301 redirects is condensing multiple pages into one. Often times a site will have several pages with very thin or similar content, with nearly identical URL structures and title tags. Choosing the more established page and permanently redirecting the others will help to build additional page authority and link juice, as well as prevent any duplicate content. By getting rid of irrelevant or near-duplicate pages and instead focusing on one, you can focus on a single, highly valuable piece of content and create a better experience for visitors.
If you’re using WordPress, make it even easier with the Simple 301 Redirects plugin.

Create Custom Error Pages

Reddit Error Page

Custom error pages provide a great opportunity to be creative and show a bit of your personality. Reddit does a great job of this (pictured right).
Whatever route you take, be sure to also include links to the main sections of your site.
Specify your error page locations

ErrorDocument 400 /400.html
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html

404.html should be replaced with the actual page name you wish to use as your 404 page. The same holds true for the other four.
How it impacts SEO
In short, it keeps visitors on your site. When visitors arrive at a default error page, their initial instinct is to hit their “back” button and try another site instead. By setting up custom error pages, it gives you the chance to keep visitors on your site by instead providing them with helpful links they can follow (and perhaps a bit of humor!).

Prevent Unauthorized Directory Browsing

If not disabled by default, it’s usually best to disallow directory browsing. If you have a folder called /secret, for example, but no default index page, people will be able to browse the entire contents of the folder if directory browsing is enabled.
Disable directory browsing

Options All -Indexes

If you wish to enable directory browsing, that can be done as well.
Enable directory browsing

Options All +Indexes

Save Your .htaccess File Properly

Because .htaccess is the extension, that’s how you should save the file. It’s not htaccess.html or index.htaccess; it’s simply .htaccess.
When you go to save the file, choose “Save as type: All types (*.*)” and name it .htaccess. Upload it to your root directory.

Additional Resources

For additional reading and to learn about all of the functions that can be accomplished through .htaccess, refer to the following links:
W3Schools Forums
Perishable Press