InMotion Hosting Support Center

You may have heard about how adding a 'rel="canonical"' tag to the head of an HTML file can improve your SEO. And we all need to give our SEO a tune-up once in a while. This tag can be helpful if you have many versions of the same page, creating duplicate content (which is bad for SEO). Often, this can happen if the site's code allows multiple URLs to generate the same page.

The 'rel="canonical"' tag helps your SEO by telling search engines what URL is the official (or, canonical) one. It's like a pointer that refers the search engine to the canonical URL. And you can do this with your .htaccess file!

What about images and PDF files?

It's true that static files like images and PDFs don't have an HTML head area where you can put a canonical URL. Imagine that your site has thousands of images that have been indexed by Google. It's possible someone might land on your image while searching.

Is there any SEO value in that? There can be, if you put a canonical URL for that image in the HTTP response headers. Follow along below and we'll show you how to do that with your .htaccess file.

How to Canonicalize Images and PDFs

For the example below, let's suggest that the image name has a corresponding HTML page of the same name. If anyone lands on that image, the HTTP response header will provide our canonical URL for the page associated with that image:

Options +FollowSymlinks
RewriteEngine On

RewriteRule ([^/]+)\.jpg$ - [E=FILENAME:$1]

<FilesMatch "\.jpg$">
      Header add Link '<{FILENAME}e.html>; rel="canonical"'

You can use the same code for PDFs or other file types, just change the file extension provided.

You could also add this header to individual files:

<Files image.jpg>
      Header add Link '<>; rel="canonical"'

In the above, the URL is dynamically generated, and in the below, it's hard-coded. You can use whichever way works best for your site.

How do you know it's working?

You can test this procedure by opening your browser's inspector or debugger and viewing the HTTP response headers. (How to do this will vary for different browsers.)

This code (slightly modified) can be placed in your Apache configuration, but that requires root access. For accounts that don't have root, like our Business Hosting accounts, the .htaccess file is the best place to do this.

Was this article helpful?

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Forum Login

You are NOT logged in. You can still browse our Support Center.

To participate within our Community Support Forum:

Post a Comment

Email Address:
Phone Number:

Please note: Your name and comment will be displayed, but we will not show your email address.

0 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?


Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail:
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!