MENUMENU
  • Services
    • Services
      • Search Engine Optimization
      • International Search Marketing
      • Local Search Marketing
      • Pay Per Click Advertising
      • Social Media Marketing
      • Email Marketing
      • Conversion Rate Optimization
      • Public Relations
      • Website Design & Development
      • Reporting & Analytics
      • Amazon Marketing Services
      • Digital Marketing Strategy
      • Franchise Marketing
  • Case Studies
  • About Us
    • About Ignite Visibility
      • Our Story
      • Clients
      • Our Values
      • Diversity & Inclusion
      • Our Team
      • UCSD Extension Courses
      • Careers
  • Thought Leadership
      • Our Blog
      • Podcast
      • SEO: The Movie
      • Social Media Marketing: The Movie
      • Book: The Forecaster Method
      • Attend Our Next Digital Marketing Event
  • Contact
  • 619.752.1955
Home / SEO Rankings / The Ultimate Guide to htaccess Files for SEO

The Ultimate Guide to htaccess Files for SEO

February 11, 2020 By John E Lincoln

For customized website performance and function .htaccess files allow developers to override or enable the main server configurations on web server software. By replacing the main server’s configuration files with your own, the .htaccess file is loaded to the web server. It’s then detected and executed by the server to alter the configuration of the software for custom functionality and features that the software typically doesn’t offer. By configuring certain server files, SEO performance is increased as you‘re able to customize areas the server may not offer.

The Ultimate Guide to .htaccess Files for SEO

The Ultimate Guide to
.htaccess Files for SEO

  • How .htaccess Files Help SEO
  • SEO-Friendly URLs .htaccess
  • Overriding CMS URLs
  • Removing .html and .php
  • Adding rel=“canonical” to PDFs and Headers
  • Utilizing .htaccess for improve site speed
  • Developing Various Redirects
  • Redirecting to the Latest Website Version’
  • Solving 404 Errors with 301 Redirects
  • Caching for Site Speed
  • Robot Directives
  • Sending Spiders to Sitemap
  • Configuring .htaccess Files

How Do .htaccess Files Help SEO?

Configuring the main server’s files will directly result in better SEO because you’ll be spotted by more search engine spiders and increase how well your website functions. By replacing the standard files with your own, you’ll produce cleaner URLs, resolve missing 404 status codes, produce better 301 redirects, and boost the cache of your website. There are many useful codes every web developer should know when dealing with .htaccess files.

Creating SEO-Friendly URLs .htaccess

You need to have clear and concise SEO-friendly URLs that include keywords to draw more traffic from search engines as Matt Cutts verifies that keywords in your URL are used as a ranking factor. Not to mention, URLs need to be as short and to the point as possible for internet users to remember them easily and understand where a link is taking them.

Clean up the appearance and function of your URLs by overriding the current URLS on a file-by-file basis as extensions are used to identify and handle URLs.

Working with https://site.com/index.php?topic=article as an example, use htaccess code:

RewriteEngine On

Rewrite Rule ^topic/ (a[a-zA-Z0-9]+)$ index.php?topic=$1

Thus, changing the previous URL to https://site.com/rules/article.

Overriding CMS URLs

There are a few instances where a CMS won’t allow for easy customization of URLs. You’re able to find your around the CMS’s restrictions with .htaccess files using:

RewriteEngine On

Rewrite Rule (.*)/$load_page.php?&page_id=$1

Upon uploading the new file, the URL will appear much cleaner and perform better for SEO, appearing as: site.com/contact-us

Removing .html and .php

Although Matt Cutts recommends keeping file extensions, such as .html, many don’t like the appearance and want the extension removed. To remove .html and .php extensions use .htaccess code:

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME}.html -f

Rewrite Rule ^(.*)$ $1.html

To remove .php, you’ll just swap .html with .php in the above code. Be sure to remove the extension from all of your internal links as well.

Adding rel=“canonical” to PDFs and Headers

In 2011, Google announced their support of adding rel=“canonical” relationships with specific HTTP headers to signal canonical URLs for HTML documents, including PDF files. When placed in the head section of an HTML page, it’s an alternative method to point images and PDFs to HTML versions, such as a page where downloading a PDF document is available.

For PDF files using HTTP headers, you’ll use the code below to point the PDF file to the HTML page using the /page.html URL.

<Files “file.PDF”>

Header and Link “<htttp://www.site.com/page.html>; rel=”canonical””

</Files>

Utilizing .htaccess for improve site speed

This can be done by leveraging browser catching in a few ways:

  1. Using a Cache-Control header
  2. Compressing your site
  3. Utilizing an ExpiresByType

Developing Various Redirects

Configuring .htaccess files will resolve multiple issues with redirects, such as redirecting visitors to the correct version of your website, 404 redirects, and 301 redirects. You never want a website visitor to end up on a blank page due to a broken URL, which is why you need to establish great redirects that abide by the latest algorithm updates.

Whether you need to create a custom 400 for a bad request, 401 for authorization required, 403 for forbidden directory, or 500 for internal server error, the code is simple to send visitors to the right path using:

ErrorDocument 402 /temp/page-temporarily-unavailable402

For 400, 403, and 500 redirects, simply change the number in the above code to properly redirect.

Redirecting to the Latest Website Version

For whatever reason, a search engine may be indexing multiple versions of your homepage. To sort the confusion for search engines and to send website visitors to the most recent version of your website, you need to tell search engine spiders where to go with a 301 redirect.

To change the www. version with a 301 redirect use .htaccess code:

RewriteCond %{HTTP_Host} ^site.com$ [NC]

RewriteCond ^(.*)$ https://www.site.com/$1[R+301,L]

RewriteCond %{THE_REQUEST} ^.*/index

Rewriter ^(.*)index$ https://www.site.com/$1 [R=301, L]

If you prefer a naked URL without the www., use the above code but leave out www.

Solving 404 Errors with 301 Redirects

We all know 404s can’t always be avoided, but you can resolve a 404 error with a 301 redirect. As a result, no one will ever see the 404 error because you’ll bring older website pages to newer website pages. This will work for all search engines, not just Google, to allow all of your pages to be indexed. It will also solve the issue of any website that may have linked to your older pages, so there won’t be any broken links as they will be redirected.

Redirect your older URLs to newer URLs using:

Redirect 301/information/your-article https://www.site.com/articles/your-article

Caching for Site Speed

You will improve your website’s speed by adjusting caching. Caching involves a browser storing certain resources, like images and text files, which are triggered when a visitor heads to your website. You’re able to adjust how the browser reacts when an internet user visits your website using mod_expires and mod_headers, providing you with greater control over the caching process.

To adjust the expiring time, use .htaccess code:

<ifModule mod_headers.c>

# Turn on Expires and set default expires to 2 days

ExpiresActive In

ExpiresDefault A259200

Adjust the expiring times to meet your own needs; however, remember they are calculated in seconds.

Robot Directives

You may or may not want Google to access all website pages for indexing. Restricting robots.txt and “no follow” links aren’t always an option with some CMS. If the options aren’t available, you’ll need to use .htaccess to put the “No Index Meta Robots” tags on the pages you want restricted.

For example, if you don’t want search engines to show PHP files you’ve generated, insert the following code into the header file:

Header(“X-Robots-Tag: no index”, true);

To make the links on the page “no follow,” use code:

Header(“X-Robots-Tag: no index, no follow”, true);

To directly configure the web server, use:

<Files Match “robots.text”>

Header set X-Robots-Tag “no index”

</FilesMatch>

Don’t worry about making your links “no follow” as Google says they won’t penalize for “no follow” links.

Sending Spiders to Sitemap

For a well ranking site on Google, search engine spiders need to be able to crawl the sitemap to index pages, posts, categories, and tags. If your website doesn’t allow for automatic regenerations of new sitemaps when your website is updated, add the appropriate .htaccess code. By adding a HTTP 301 Redirect, you’ll create a permanent redirect to tell search engine spiders exactly where the file is located to increase your ranking.

< IfModule mod_alias.c >

RedirectMatch 301 /sitemap.xml$ https://site.com/sitemap.xml

RedirectMatch 301 /sitemap.xml.gz$ https://site.com/sitemap.xml.gz

Configuring .htaccess Files

There are many advantages and disadvantages to editing .htaccess files. There are great benefits because the changes will be immediate to boost the functions of your site. But, if you don’t know what you’re doing, you’ll hurt the performance of your website and cause some serious damage. Not to mention, if it isn’t done correctly, it may cause security issues. If you aren’t sure what you’re doing, don’t touch it! It’s best to leave the server alone and hire a professional to configure .htaccess files correctly.

FAQs

1. What is an .htaccess file in SEO?

A .htaccess file is used to redirect, adjust HTTP headers, crawl sites, and other vital SEO functions.

2. How do I create an .htaccess file?

Creating a .htaccess file is straightforward, create the file with a text editor such as Notepad, Microsoft Word, and more.

Name the “.htaccess”, add the text you want, and upload the file using FTP client.

Once you have FTP connection move the folder to the hosting space you wish to have it in.

3. Why can’t I see my .htaccess file?

By definition .htaccess is a hidden file so it will not be viewable by accessing the web server.

4. How many .htaccess files for SEO should I have?

You should have one .htaccess file for your entire web hosting account.

 

Sources:

“Configuring .htaccess” Oregon State University

 

About John E Lincoln

John Lincoln (MBA) is CEO of Ignite Visibility (a 2017, 2018, 2019 and 2020 Inc. 5000 company) a highly sought-after digital marketing strategist, industry speaker and author of two books, "The Forecaster Method" and "Digital Influencer." Over the course of his career, Lincoln has worked with over 1,000 online businesses ranging from small startups to amazing clients such as Office Depot, Tony Robbins, Morgan Stanley, Fox, USA Today, COX and The Knot World Wide. John Lincoln is the editor of the Ignite Visibility blog. While he is a contributor, he does not write all of the articles and in many cases he is supported to ensure timely content.

You may also like:

  • Semantic Search
    What is Semantic Search? Does it Matter for SEO in…

  • What are YMYL Websites? YMYL Content, Pages, and E-E-A-T
  • SEO Chrome Extensions
    20 SEO Chrome Extensions to Download Now

  • Quality Over Quantity: The Word Count Debate for Content Length

Search Here

NEWSLETTER // SIGN UP NOW

About The Editor

John E Lincoln, CEO

John Lincoln is CEO of Ignite Visibility, one of the top digital marketing agencies in the nation and a 6x Inc. 5,000 company. Lincoln is consistently named one of the top marketing experts in the industry. He has been recipient of the Search Engine Land "Search Marketer of the Year" award, named the #1 SEO consultant in the USA by Clutch.co, most admired CEO and 40 under 40. Lincoln has written two books (The Forecaster Method and Digital Influencer) and made two movies (SEO: The Movie and Social Media Marketing: The Movie) on digital marketing. He is a digital marketing strategy adviser to some of the biggest names in business. John Lincoln is the editor of the Ignite Visibility blog. While he is a major contributor, he does not write all of the articles.

LEARN MORE ABOUT JOHN

Contact Us. Let’s Chat!

  • Hidden

Marketing Guides

SEO In 2020: How To Prepare For Major Disruption

"SEO: The Movie" - Have You Seen Our Film? Watch Now

"Social Media Marketing: The Movie" - Have You Seen Our Film? Watch Now

Amazon Seller Central vs Vendor Central

Listen To The Podcast Featuring The Best Minds In Marketing

John Lincoln Interviews Global Director of Digital Marketing & Strategy at Qualcomm, Jessica Jensen

Check Out 227 Free Online Marketing Classes

The 2020 Guide To Dominating SEO With Advanced Schema

Learn More About Our Digital Marketing Agency

Learn More About Our SEO Services

Learn More About Our Paid Media Services

SELECT CATEGORY

Become A Contributor

Interested in writing for Ignite Visibility?

APPLY NOW

Services

  • Search Engine Optimization
  • Pay Per Click Management
  • Conversion Rate Optimization
  • Website Design & Development
  • Social Media Company
  • Public Relations
  • Amazon Marketing Services
  • Franchise Marketing
  • International Services
  • Digital Marketing Agency Services

About

  • Our Team
  • Our Values
  • Clients
  • Reviews
  • UCSD Extension Courses
  • Careers
  • Tools & Resources
  • Sitemap

Contact

4250 Executive Square, Suite 100
La Jolla, California 92037

619.752.1955

Join The Newsletter

Sign up for our newsletter to get the latest from Ignite Visibility.

google parther logo

©2023 Ignite Visibility. All Rights Reserved. Privacy Policy