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 domain.com to www.domain.com

 

RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$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 http://www.domain.com/index.html . At the same time homepage is accessible under domain as http://www.domain.com . 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 http://www.domain.com/$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 http://www.domain.com/new_file.html

 

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

 

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteRule ^index.html http://www.domain.com/$1 [R=301,L]
Redirect 301 /old_file.html http://www.domain.com/new_file.html
Redirect 301 /old_dir/file.html http://www.domain.com/new_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 www.domain-to-use.com, then do a 301 redirect to that domain.

 

Sharing is caring!

Popular

COVID-19 Crisis Navigator​

In partnership with Dentsu, Cardinal Path helps you distill the overwhelming news and information into a bi-weekly report highlighting emerging trends and insights during the pandemic.

EXPLORE THE REPORT

Thank you for your submission.

Message Sent

Thank you for registering.

Message Sent

Success!
Your message was received.

Thank you.

Message Sent

Thank you.

Message Sent

Thank you

Message Sent

Thank you.

Message Sent

Thank you

Message Sent

Thank you

Message Sent

Thank you.

Message Sent

Thank you.

Message Sent

Thank you for registering.

Message Sent

Thank you.

Click here to download access the tool.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Thank you for submitting the form.

Thank you for submitting the form.

Cardinal Path hosted a live session to connect with you and answer all your questions on Google Analytics.
Get all the expertise and none of the consultancy fees in this not-to-be-missed, rapid-fire virtual event.

Thank you for registering.

Cardinal Path is continuing with its series of free training. Next we are conducting training on Google Data Studio. Check it out here.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for your submission.

Message Sent

Thank you for registering.

You will receive a unique link to view the webinar via email.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Success! Thank you
for reaching out.