Redirect index.php

We ran in one small issue on our live-server.

We force https and www and we must use RewriteBase / on our environment. If we have a request like http://domain.de/xyz Kirby redirects to the https://www.domain.de/index.php. Definitely one issue with our server setup, because it works in our local environment.

Currently I use the following rule at the bottom of our Redirect-Rules:

RewriteRule ^index.php$ https://www.domain.de [R=301,L]

Is there a better way to define the root as default instead of the index.php, to remove the problem with duplicated content for seo crawlers?

But shouldn’t http://domain.de/xyz redirect to https://www.domain.de/xyz instead of the homepage?

You can use the following RewriteRules to achieve this:

# Rewrite everything to HTTPS
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Rewrite non-www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
1 Like

Ah, thanks!

But shouldn’t http://domain.de/xyz redirect to https://www.domain.de/xyz instead of the homepage?

Sure, it would be great. :slight_smile:

I will test your version asap.

My current approach was:

# Redirect from the `http://` to the `https://` version of the URL.

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{SERVER_ADDR} !=127.0.0.1
RewriteCond %{SERVER_ADDR} !=::1
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Source: https://github.com/h5bp/server-configs-apache/blob/master/dist/.htaccess#L345-L385