Redirects from www pages to /index.php

Hi all.

On a simple Quark install without much customization at system config level, all is working fine, including all redirections to https://, except redirections from WWW to non WWW for inside pages only.

Page will redirect to :frowning_face: instead of

Same behavior for and,
and same for all inside pages.

How can WWW be redirected to /index.php ??? :frowning_face:

Redirections in .htaccess are as follows, identical to on my other Grav sites :

# Remove trailing slash from non-filepath urls
RewriteCond %{REQUEST_URI} /(.+)/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ [R=301,L]

# Include trailing slash on directory 
RewriteCond %{REQUEST_URI} !(.+)/$
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)$$1/ [R=301,L]

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

Error pages, as long as there is no WWW, correctly redirect from
nothing or http:// or https:// to

I have never seen this on a Grav site. I suppose something is happening in Grav settings but a few hours on this did not help me find the culprit.
This site have just a few special plugins and disabling them do not help. All updated. I tried to look in the webmaster console and Grav Clockwork debugger and, as much as I understand those tools, I could not see information on this.

Any brilliant idea?
Thank you if you have a hint.

1 Like

I also have this problem, but no solution. Can someone help? :pray:

I put the question on the side and have not yet found the solution. Still interested…

For me the htaccess tester by madewithlove has been a valuable tool to test htaccess rewrite rules.

When the htaccess file of the site which behaves bad is identical to your other sites then the difference must be in the Grav config. Especially look for any redirection routes.

Without you sharing these config files here there is not much we can do to help.


Thank you @bleutzinn for your suggestion.
As there were many red errors in my test, I decided to start from scratch with default Grav .htaccess content and some step by step help from ChatGPT to add my rules.
It seems that the important suggestion was to place these kind of domain level redirections before the default Grav specific (Quark theme) rules.
I now have these rules at the beginning of .htaccess file:

RewriteEngine On

# Redirect to HTTPS and remove www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

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

# Remove trailing slash from inside pages
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [L,R=301]

# Remove possibility to view indexes of files
Options -Indexes

… followed by default Grav specific rules.

I wanted all pages to be in without trailing slashes.
It works as expected and htaccess tester now do not have any red warnings anymore.

My other Grav sites indeed had these rules at the beginning of .htaccess.