Hi,
I’m having an issue with redirects from www to non-www on my CMS Grav installation, which is a multilingual site. My configuration in the .htaccess file looks like this:
# Redirect www to non-www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=303,L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=303,L]
The problem is that every redirect from www to the non-www version, when there is /something after the main address, causes a redirect to index.php, which results in a 404 error.
Examples:
- https://www.mydomain.com/contact redirects to https://mydomain.com/index.php, which ends with a 404 error.
- https://www.mydomain.com/blog redirects to https://mydomain.com/index.php, also ending with a 404 error.
- https://www.mydomain.com correctly redirects to https://mydomain.com, which works as expected.
I’ve noticed that if I comment out these lines that redirect from www to non-www, everything works fine, but then the site is accessible with both www and without www.
In the developer tools, I can see that the redirect is happening with a 303 status code. I used a 303 code to identify whether the redirect was coming from the .htaccess file or from CMS Grav.
The site is multilingual, which might affect how Grav processes these redirects. I’ve tried various settings in .htaccess, but the issue persists. Has anyone encountered a similar problem or knows how to resolve it? Could this be a conflict with Grav’s default redirects?
Any suggestions would be appreciated.