How do you redirect index.php to root


What is the best way to redirect homepage/index.php to homepage.

Do you use htaccess file of Kirby ?

Something like this will redirect all index.php to home page, but i don’t think it is the bette practice

RewriteCond %{REQUEST_URI} index\.php
RewriteRule .* https://www.mySite/ [R=301,L]

Im not sure I get what you are trying to do. Most servers are set up to use an index as the home page. So basically index.php actually is the home page already, if its in the root. You should not have to put a redirect in place. Can you give a bit more detail? is this a custom folder setup? Also, which Kirby version are you using?

Hi James, if I visit your website with /index.php at the end of the URL, i’m redirect to the error page (Like mine) I thought that maybe for seo, it would be better to stay on the home rather than being redirected to 404 (For home only)

Lucas website is redirect to home
also Sonja etc

You can do that either in (in order of preferences) your server configuration, the .htaccess or using a route.

I think both the error page and the redirect are OK, depending on your preferences. My website doesn’t have a redirect actually, it just displays the homepage under the same URL (which should not happen, actually)

1 Like

So something like this works:

 'routes' => [
      'pattern' => '/index.php',
      'action'  => function () {
        return go('/', 301);

Yes, but as I said above, it’s better to do it in .htaccess or server config as these option kick in before PHP.

1 Like

Thank you Sonja, I’ll do it with htaccess

I’m really not sur this is the good way, but this works correctly in htaccess:

RedirectPermanent /index.php/ /

I would go with this:

RewriteRule ^index\.php$ /? [L,R=301]
1 Like

(Maybe I have some troubles with my cache CDN) but it seems that it redirects some other pages to home. My code works on local, but does not on remote.