Moving from .html to Kirby .php and SEO

I’m bringing a static hand-coded website into Kirby. Currently all the files/pages are .html. I have .htaccess file that is hiding the .html ending. I will be replicating all the pages in Kirby, but all the pages will now have a .php ending. I intend to use the .htaccess file to also hide this suffix.

My question is, will this change from .html to .php effect my search rankings? Or will search engines not notice any difference because the .html and .php endings will be hidden?

For SEO, you want to avoid any two URLs ever returning the same content at all cost (the “duplicate content” problem, which can be penalized by Google et al.).

So, instead of “hiding” the former .html suffix, you could write an htaccess rule that redirects any requests pointing to such URL to the new URL. So, a request to example.com/about.html would emit an HTTP 302 or 301 response, telling all user agents (including search engines) that the content has moved to example.com/about (Kirby does not require any php suffixes, so unless you are adding them for creative purposes, the .php is no needed?).

In addition, it is good practice to include a <link rel="canonical"> tag in your HTML’s <head> with the “canonical”, i.e. the only actual URL.

1 Like

Thanks.

In addition, it is good practice to [include a tag](https://moz.com/learn/seo/canonicalization) in your HTML’s with the “canonical”, i.e. the only actual URL.

so for this example the “actual URL” would be example.com/about with no .html or .php ending?

Would the canonical include “https://www.” ?

For SEO, you want to avoid any two URLs ever returning the same content at all cost (the “duplicate content” problem, which can be penalized by Google et al.).

I don’t think this would be the case. As soon as I’ve made my website in Kirby I’ll take down the old .html website.

Given that I’ve been hiding the .html ending would I still need to redirect to the new pages (both are example.com/about)? or do search engines still ‘see’ the hidden .html ending?

Thank you

Correct. This is usually the URL that your Kirby configuration uses by default (i.e. what $page->url() would return – which is also the easiest way to populate that link tag).

Depends on your configuration and personal preference. It can be either and it is common practice to forward one to the other, again using an HTTP 301/302 response, to ensure only one of the URLs – either with or without www. returns a HTTP 200 and the content.

The problem in your scenario described in your original post (the htaccess “hiding” the ending), if I did not misread it, is that both URLs (example.com/about.html and example.com/about) would return an HTTP 200 code and the content of the page. So Google would not be able to understand you have deleted the old pages, since the old URLs still seem to work (even though the content now “lives” under a new URL).

Thanks for bearing with me. Here is the code in the .htaccess file.

RewriteEngine On

# add www and turn on https in same rule
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]

## hide .html extension
# To externally redirect /file.html to /file
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]

# To internally rewrite /file to /file.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]

I don’t understand it. But it looks like there is a redirect from about.html to about.

Not sure what that means, or what I might have to do, in move from a static html site to a Kirby PHP site?

Hmm, this somehow seems to not be a Kirby htaccess?

Comparing this to the Plainkit htaccess template, your file does not include the crucial part that makes Kirby links work in lines 39-41. With Kirby, all traffic has to internally be routed into the index.php file. That last section in your file outright conflicts with that.

(There are also a few other really important rules in that default template that should not be omitted, such as blocking access to content files etc.)

Does that htaccess you posted above actually work with your Kirby site? :thinking:

I would suggest using the Plainkit htaccess file and add your custom sections about the www prefix (“add www and turn on https in same rule”) and the .html suffix (“externally redirect /file.html to /file”) right after the Rewrite on statement, after line 9 that is. Those two seem to be ok at first glance (I’m not the most proficient reader of offline htaccess files, mind you…), and your redirection of the old .html URLs is actually set up exactly as I suggested (it triggers a 301 redirect, not just removing it silently in the background).

Don’t copy the last section of your file (“internally rewrite /file to /file.html”); I believe this is something that may stem from your old static site setup?

This is the htaccess file I’m currently using on my static html website. This will get binned when I launch my Kirby website.

Thanks for the help

Ah of course, that was the framing I missed to make sense of it :slight_smile:

So indeed, copying over this part

# add www and turn on https in same rule
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]

## hide .html extension
# To externally redirect /file.html to /file
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]

to the Kirby htaccess should have you covered re your original question, as your “public URLs” never really contained a .html suffix in the first place (your current setup hid that). And indeed, no .php URL suffixes should ever surface anywhere, as Kirby takes URLs without any file endings and channels them into its own index.php in the background.

I’ve finally worked my way down my to do list and got to this.

I presume I don’t need to add the following to my .htaccess file, because Kirby doesn’t create any .html files, so there won’t be any .html extensions to hide / redirect to?

## hide .html extension
# To externally redirect /file.html to /file
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]