Old http URLs redirecting to index.php

I’m wondering if I’m doing something wrong, or if this just isn’t possible with Kirby.

The trouble started when I installed a single ssl cert for my domain, with www. When adding code to force https and www I noticed a pattern where only Kirby pages would redirect to index.php when using http:// and no www.

Relevant .htaccess snippet (full file below):

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.andybeckmann\.com$ [NC]
RewriteRule ^(.*)$ https://www.andybeckmann.com/$1 [L,R=301]   

I tested my htaccess code by adding a folder with a generic index.html to my site root, and my htaccess code seems to work as expected. This leads me to believe this is an issue with Kirby losing the URI. Here’s what I’m experiencing:

Non-Kirby directory:


redirects to:


as expected.

Kirby page:


redirects to:


The site itself is simple. I only have one route set up for a sitemap.xml in the site/config/config.php and I’m not using any plugins.

Full .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]    


# 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

# 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

Let’s start with putting the http/https redirects at the beginning of the file.

1 Like

Thanks for the suggestion. That fixed it. Resolved.


what do I have to do, to redirect the user to the index.php, when he is entering an old URL which isn’t existing anymore. I tried redirect 301 in the htacces file but it didn’t work.

Thank you.