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 ^(.*)$ https://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 https://www.domain.com/index.html . At the same time homepage is accessible under domain as https://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 https://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 https://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 ^(.*)$ https://www.domain.com/$1 [L,R=301]
RewriteRule ^index.html https://www.domain.com/$1 [R=301,L]
Redirect 301 /old_file.html https://www.domain.com/new_file.html
Redirect 301 /old_dir/file.html https://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.

Message Sent

Thank you for registering.

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 submitting the form.

Thank you for submitting the form.

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.

Click here to download access the tool.

Message Sent

Thank you for registering.

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

Success!
Your message was received.

Thank you.

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.

Thank you for your submission.

Your request has been submitted and a rep will reach out to you shortly.

Message Sent

Thank you for your interest.

Thank you for registering.

You should receive a confirmation email from GoToWebinar with your unique webinar login information. If you do not receive this email or have trouble logging in to the event, please email asmaa.mourad@cardinalpath.com.

Thank you for subscribing!

You're now looped into the world's largest GMP resource hub!

Thank you for your submission.

Thank you for your submission.

Thank you for your submission.

Thank you for your submission.

Message Sent

Thank you for registering.

Message Sent

Thank you for your submission.

Thank you for your submission.

Message Sent

Thank you for registering.

Thank you for registering.​

Paid media spend by Government websites increased a whopping 139% YoY in 2020.

2020 Online Behavior Live Dashboard

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

2020 Online Behavior Live Dashboard

Thank you for your submission.

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

Success! Thank you
for reaching out.