Cardinal Path’s response to COVID-19 Cardinal Path is sharing all we know to help marketers during COVID-19.  Learn more.


This was originally posted in 2008, but not a lot has changed. Given how many times we’ve seen improper redirects during our SEO Mistakes series, we’ve decided that this deserves a repost. Enjoy.

Apache server provides a great feature to help webmasters with SEO. This feature is htaccess file. This file is located in the root of websites and provides additional setting information to server. Webmasters have access to this file and can easy adjust it for specific needs.

Let’s take a look how htaccess can help optimize website hosted on Apache server.

1. There are many discussions about non-www and www versions of websites. What version is better for SEO? Neither is better. Just choose one version and stick with it. It will help search engines do not index the same pages under different URLs (with and without www).

Example below redirects from to


RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]


Please note that Google Webmaster Central has a tool to select preferred version of domain (with or without www).

2. Many websites have internal links pointed to homepage of website as . At the same time homepage is accessible under domain as . As result, search engines could index homepage (the most important page on website) under 2 different URLs. One line of htaccess code helps avoid or fix it.


RewriteRule ^index.html$1 [R=301,L]


3. What to do if you want to move a web page in different directory or rename file/directory? Think about that twice. Do you really need it? It’s better to keep URLs of all pages stable and don’t change it. In case you have to move/rename page or directory make sure you setup permanent (301) redirects from old URLs to new ones. Code below shows an example of this redirect.


Redirect 301 /old_file.html


Code below shows an example of htaccess file that includes all lines we reviewed above


RewriteEngine on
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]
RewriteRule ^index.html$1 [R=301,L]
Redirect 301 /old_file.html
Redirect 301 /old_dir/file.html


Make sure you test website after any update of htaccess file. Wrong code or any mistake can put down entire website.

From David Eckman, left in the comments:

One other type of 301 that wasn’t discussed is when you want to do a redirect from one URL to another within the same hosting account. This ensures that everyone must use a single domain to access your site.

The code for doing this is below:


What this basically says, is that if the domain used to access the site is NOT, then do a 301 redirect to that domain.



State of Digital Marketing Analytics

The 2020 State of Digital Marketing Analytics examines the marketing technology that supports the world's most successful enterprises and highlights the challenges and strategies for navigating the new normal..