Support for .html url

Is it possible to setup Kirby with url ending with .html?

You could change your .htaccess to do that, maybe this helps:

But then again I am wondering, why you would want to do that…

Thanks for the answer Distantnative. It helps indeed but the links inside the website would still remain without extension.
I am concerned about SEO in fact. Kirby does not seem to understand an url like :
So maybe the solution is the other way round : make Kirby understand url with extensions, with routing maybe?

I’m with @distantnative on this, I’m not quite sure what your trying to accomplish. Why is there a …com/home.html file at all? What purpose does it serve over creating a page in the CMS named “home”, which will be located at …com/home?

If you really want to use flat HTML in your page, you can do that with markdown extended.

You could create a template with the following:

<?php echo $page->text()->kirbytext(); ?>

and add HTML to the page’s “text” field.

I’ve done this in specific situations where it was a quick and simple solution for easy updates on a production server. It makes me feel dirty, but it works.

I’m sorry if I was not clear enough. I’m not familiar with urls without extensions.
@Luke : regarding the “home.html”, it was an exemple. I was pointing at .html, not “home”.
I am also reluctant to use a name including the extension (the quick fix).
The point for me was not to loose urls from a previous website. I guess I’ll have to find another method to keep them.
By the way thanks for the piece of information guys.

I think that in this case instead of trying to mimic the old urls you could just permanently redirect the old urls to the new ones in your .htaccess, like @plaidpowered suggested in his withdrawn post.

@texnixe I just couldn’t find any way to relay the information without sounding adversarial, and everybody is just so nice around here, I didn’t want to give the wrong impression. :slight_smile:

1 Like


Let’s say your old site has a file named contact.html, and you want to retain the page in your search rankings. Firstly, create a page in Kirby with the URL of contact. Do this for as many pages as you have, just take off the “.html” when you enter the URL of your new pages.

Second, add this to your .htaccess file, right before </ifmodule>:

RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ $1 [R=301,L]

What this will do is tell your webserver to automatically redirect the old .html URL’s to the new pages. So you won’t have any dead links, and you won’t lose any SEO points.

If anybody wants to check my syntax? Please do. I just wrote this off the top of my head, and didn’t test it.

I’ll definitely go in this redirection : using .htaccess + eventually the routing function of Kirby in order to keep my previous url to the new system.
Thanks to all of you for giving me a solution beyond my question.

Awhile ago I created a redirect setup with panel support. You can take a look and try it out if you’d like.

blueprint: redirects.php

<?php if(!defined('KIRBY')) exit ?>

title: Redirects
    - _redirect
files: false
    label: Title
    type:  text
    label: Add to sitemap?
    type:  toggle

blueprint: redirect.php

<?php if(!defined('KIRBY')) exit ?>

title: Redirect
pages: false
files: false
    label: Title
    type:  text
    label: URL In
    type:  text
    label: URL Out
    type:  text
    label: Force Prod
    type: toggle
    text: on/off
    label: Add to sitemap?
    type:  toggle

PHP to include on each page:

//    Redirects
$GLOBALS['rdir']                        = $pages->find('redirects');
$GLOBALS['rurl']                        = "$_SERVER[REQUEST_URI]";

foreach($GLOBALS['rdir']->children() as $r):
    $url_c = str::lower($GLOBALS['rurl']);
    $url_i = str::lower($r->url_in());
    if(str::contains($url_o, '') || str::contains($url_o, 'YOURSITE.local')) if($r->url_prodonly() != 'true') if(c::get('env') != 'prod'): $url_o = 'https://' . c::get('env') . $url_o; else: $url_o = 'https://' . $url_o; endif;
    $pos = strpos($url_c, $url_i);
    if ($pos !== false && $url_c === $url_i || $pos !== false && $url_c === $url_i . '/'): go($url_o); endif;

This was setup for multiple environments which you may not need, and SSL. You can modify it or add this to your config.php file.


Thank you Luke. I’ll give it a try. :smile:

This .htaccess rule with result in a 301 Redirect RewriteRule ^(.*)\.html$ $1 [R=301,L], and you will be losing Link Juice if you are migrating an old website
with pages of say contact.html => contact.

From articles about 301 redirects and its effects when doing site migrations you will be losing from 1-9% of your link juice which depending on your traffic might cause quite a lot of damage on your Ranking Power.