Kirby Update v1 to v2 breaks site

Hi guys,

I tried to update an old site of mine today from Kirby 1 to Kirby 2. Sadly it breaks my site. I either get a blank page or the dreaded “Too many redirects”. Though at the moment I am stuck at the blank page. I went by the Updating guide from the docs, deleted the old Kirby and Panel folders and replaced them with updated versions from GitHub. Same with index.php and the .htaccess file. I moved around the /panel/ folders as instructed.

The only peculiarity with this site is that it is in a subfolder.

But I have set my config.php to c::set('url', ''); and my .htaccess to RewriteBase /site

All else is pretty much a vanilla Kirby. No plugins, no extensions.

What else could I be missing? I’d appreciate any help I can get on this one.

Is there anything in the error logs? If you don’t have access to the php error logs, could you try to enable debug in your config.php?

Looks like it was a case of me being really stupid. I was deploying with Git, but completely forgot that submodules do not get pushed by default. Which means I ended up with empty kirby and panel folders on the server. So much for being smart and using version control. :blush:

However, now that that is out of the way I am back at “Too many redirects”. :frowning:

Nothing in the error logs I am afraid.

Now I am getting somewhere. I can access the debug page.

It seems to complain about one of my snippet files:

Whoops \ Exception \ ErrorException (E_ERROR) Call to a member function title() on boolean

the line it complains about:

<link rel="alternate" type="application/rss+xml" href="<?php echo url('blog/feed') ?>" title="<?php echo html($pages->find('blog/feed')->title()) ?>" />

Looks like the page /blog/feed does not exist.

I’ve deleted the offending line (it was not needed and I have no idea what it was doing in there in the first place). Now I am back at “Too many redirects”. This feels like chasing my tail. I might just go back to using the old Kirby install.

I am able to open the site by going the the index.php directly.

Seems to be a pure .htaccess issue at this point. I am using the starterkit one with the only change being RewriteBase /site.

Have you tried with removing the url setting in the config? and setting the RewriteBase to “/”.

Also it’s a pain but when a browser has received a HTTP redirection once it may keep it in cache and reapply it automatically (for a 301 redirection). When I have those kind of issues I keep clearing the cache, opening “Private” windows for testing, etc. Sometimes it’s easier to use a command-line tool like curl to see what response you’re actually getting.

Edit: I think Firefox or Chrome with the devtools open and the “Ignore cache when devtools are open” option checked could work to avoid that. The Network panel is your friend.

I just did and am still getting “Too many redirects”.

Hm, do you have another .htaccess in the root? Why does your domain redirect to the subfolder? Then you might as well put Kirby in the root or point the domain to the subfolder? Or is it intentional that you want “site” in the URL for some reason?

yes, that is intentional. this is a shared host and the root houses all the subdomains on this shared hosting account. so to keep my “main” site apart from all the subdomains and other technical clutter in the root directory I have been running the site from /site so far. Also so far without problems under Kirby 1.

The root has a .htaccess in it that handles all the subdomain redirects. It is mostly created by the cPanel of the shared host.

So it mostly looks like this:

RewriteCond %{HTTP_HOST} ^alexanderkucera\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.alexanderkucera\.com$ RewriteRule ^/?$ "http\:\/\/www\.alexanderkucera\.com\/site\/" [R=301,L]

To make sure that this is not caused by something in your code, you could test with a fresh starterkit. If the issue persists, we at least know that it’s not something in your code.

But it might be that the redirect loop is caused by the redirect from the .htaccess in the root folder.

I uploaded a vanilla starter kit to my /site folder and still get the “Too many redirects”. If I remove the .htaccess from the starter kit the site’s homepage works. Though the navigation is broken.

I tried the same with my site and removing the .htaccess file also makes the homepage work with a broken navigation.

Yes, but the homepage only works with “index.php” in the URL. Have you tried to set the rewriteBase in the Kirby .htaccess again and/or the URL in config. Maybe you have to play a bit with these settings (and make sure that the cache is cleared in between).

The culprit seems to be this line:

RewriteCond %{REQUEST_FILENAME} !-d

If I comment that out the site loads as expected and the subpages seem to work as well.

I’d say that the culprit is your rewrite rules that say “if the domain is mydomain, redirect to mydomain”, which is bound to create an infinite loop. :thinking:
When I hit up http://mydomain/site/, the domain is mydomain, so I will get redirected.
Your rewritecond should check that the URL does not already contain “/site”.

Could be also that your rewriterule does one redirect, then Kirby’s rewriterules do another one, then yours does a redirect, then Kirby, then you, then…

How would that corrected rewrite rule look like? The point of

RewriteCond %{HTTP_HOST} ^alexanderkucera\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.alexanderkucera\.com$ RewriteRule ^/?$ "http\:\/\/www\.alexanderkucera\.com\/site\/" [R=301,L]

as far as I understand it is to redirect any top level requests (e.g. to
I don’t see a way around that since the Kirby htaccess lives inside the /site/ folder and has no influence on what happens when a visitor tries to visit

You’re right, I had misread the ^/?$ part. My bad.