I am using the following in my .htaccess file to force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
This works perfectly for all pages except one page - /workbook
When visiting http://whatdoesittaketowin.com/workbook you are redirected to /index.php rather than added the correct https prefix like it does on all other pages.
This only happens when http and no www are used. If http and www are used together it does works. No other page on the website is behaving like this, just /workbook.
Additionally if a change the URL to something else ie /workbooktest it redirects correctly, but changing the URL isn’t possible as it’s linked in a physical book.
What could be different about this particularly URL that Kirby doesn’t like?
If I enter that URL in my browser, it correctly redirects to https://www./whatdoesittaketowin.com/workbook
. Maybe some browser caching on your side?
I have a very similar problem. Here’s my example:
Incorrect:
http://andybeckmann.com/contact
redirects to index.php
Correct:
http://andybeckmann.com
redirects to
https://www.andybeckmann.com
This next part seems like it could be related, but is also a little different:
In Chrome
https://andybeckmann.com/projects
redirects to
https://www.andybeckmann.com/projects
adding www correctly, but in FireFox I’m seeing the error code SSL_ERROR_BAD_CERT_DOMAIN because the cert is for www only.
The cert is through Let’s Encrypt.
My .htaccess looks like this:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.andybeckmann\.com$ [NC]
RewriteRule ^(.*)$ https://www.andybeckmann.com/$1 [L,R=301]
I looked through that link and tried a few of the suggestions but nothing was working.
I decided to do a test by adding a folder with a generic index.html to my site root, and my htaccess code works as expected. This leads me to believe this is an issue with Kirby losing the URI.
Regular folder:
http://andybeckmann.com/test-folder
redirects to:
https://www.andybeckmann.com/test-folder
as expected.
Kirby page:
http://andybeckmann.com/contact
redirects to:
https://www.andybeckmann.com/index.php
So I am back to my original code and wondering if I’m doing something Kirby can’t handle, as it seems to work as intended:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.andybeckmann\.com$ [NC]
RewriteRule ^(.*)$ https://www.andybeckmann.com/$1 [L,R=301]
Could you please post the complete .htaccess
file? Also, what’s going on in custom routes (config/plugins)?
.htaccess
# Kirby .htaccess
# rewrite rules
<IfModule mod_rewrite.c>
# enable awesome urls. i.e.:
# http://yourdomain.com/about-us/team
RewriteEngine on
# make sure to set the RewriteBase correctly
# if you are running the site in a subfolder.
# Otherwise links or the entire site will break.
#
# If your homepage is http://yourdomain.com/mysite
# Set the RewriteBase to:
#
# RewriteBase /mysite
# In some environments it's necessary to
# set the RewriteBase to:
#
RewriteBase /
# block files and folders beginning with a dot, such as .git
# except for the .well-known folder, which is used for Let's Encrypt and security.txt
RewriteRule (^|/)\.(?!well-known\/) index.php [L]
# block text files in the content folder from being accessed directly
RewriteRule ^content/(.*)\.(txt|md|mdown)$ index.php [L]
# block all files in the site folder from being accessed directly
# except for requests to plugin assets files
RewriteRule ^site/(.*) index.php [L]
# Enable authentication header
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
# block direct access to kirby and the panel sources
RewriteRule ^kirby/(.*) index.php [L]
# make site links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]
</IfModule>
# compress text file responses
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>
# Force SSL and WWW
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.andybeckmann\.com$ [NC]
RewriteRule ^(.*)$ https://www.andybeckmann.com/$1 [L,R=301]
# Rewrite old page URLs
# Redirect 301 /old https://www.andybeckmann.com/new
Redirect 301 /portfolio https://www.andybeckmann.com/projects
Redirect 301 /about https://www.andybeckmann.com
Redirect 301 /privacy https://www.andybeckmann.com
Redirect 301 /suggestions https://www.andybeckmann.com
Redirect 301 /blog/2016/04/05/hello-world https://www.andybeckmann.com/blog/hello-world
Redirect 301 /blog/2016/04/06/fixing-issues-with-handbrake-in-mac-os https://www.andybeckmann.com/blog/fixing-issues-with-handbrake-in-mac-os
Redirect 301 /blog/2016/04/28/exporting-images-from-adobe-photoshop https://www.andybeckmann.com/blog/exporting-images-from-adobe-photoshop
Redirect 301 /blog/2016/05/05/fix-path-issues-on-localhost-with-php https://www.andybeckmann.com/blog/fix-path-issues-on-localhost-with-php
Redirect 301 /blog/2016/05/22/thoughts-on-future-of-tcp https://www.andybeckmann.com/blog/thoughts-on-future-of-tcp
Redirect 301 /blog/2016/05/30/thoughts-on-decentralized-tech https://www.andybeckmann.com/blog/thoughts-on-decentralized-tech
Redirect 301 /blog/2016/06/26/12-million-ether-has-been-stolen https://www.andybeckmann.com/blog/12-million-ether-has-been-stolen
Redirect 301 /blog/2016/07/09/hacker-wars-kypertech-vs-hashocean https://www.andybeckmann.com/blog/hacker-wars-kypertech-vs-hashocean
Redirect 301 /blog/2016/07/11/new-ethos-background-designs https://www.andybeckmann.com/blog/new-ethos-background-designs
Redirect 301 /blog/2016/07/20/ethereum-successfully-implements-hardfork https://www.andybeckmann.com/blog/ethereum-successfully-implements-hardfork
Redirect 301 /blog/2016/07/20/update-on-kypertech https://www.andybeckmann.com/blog/update-on-kypertech
site/config/config.php:
<?php
return [
'debug' => false,
'routes' => [
[
'pattern' => 'sitemap.xml',
'action' => function() {
$pages = site()->pages()->index();
// fetch the pages to ignore from the config settings,
// if nothing is set, we ignore the error page
$ignore = kirby()->option('sitemap.ignore', ['error']);
$content = snippet('sitemap', compact('pages', 'ignore'), true);
// return response with correct header type
return new Kirby\Cms\Response($content, 'application/xml');
}
],
[
'pattern' => 'sitemap',
'action' => function() {
return go('sitemap.xml', 301);
}
]
],
'sitemap.ignore' => ['error'],
];
plugins/gallery/index.php:
<?php
Kirby::plugin('starterkit/gallery', [
'hooks' => [
'kirbytags:after' => function ($text, $data, $options) {
if ($page = $data['parent']->gallery()->toPage()) {
$gallery = snippet('gallery', ['gallery' => $page], true);
} else {
$gallery = '';
}
return str_replace('{{ gallery }}', $gallery, $text);
}
]
]);
I think that plugin is leftover from the starter build.