Panel login failure when changin the .htaccess-file to redirect non-www to www


Unfortunately, since I changed the .htaccess-file to redirect all non-www to www, the panel won’t let me log in anymore but just redirects to the panel without any error-message.

My .htaccess-content is:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteRule ^content/(.*)\.(txt|md|mdown)$ index.php [L]

RewriteRule ^assets/plugins/([a-zA-Z0-9\.\-_%=]+)/(.*)$ site/plugins/$1/assets/$2 [L,N]
RewriteCond $1 !^plugins/[a-zA-Z0-9\.\-_%=]+/assets/.*
RewriteRule ^site/(.*) index.php [L]

RewriteRule ^(kirby|panel\/app|panel\/tests)/(.*) index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^panel/(.*) panel/index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]

Sorry if this is a very basic question, but I’m not very good in writing .htaccess-content.

Thanks for your wisdom!

Try this instead:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Is that on shared hosting or your own server with access to the server configuration?

Thanks, that worked!
www redirects to non-www now though, but I’ll just leave it like that.

(It’s shared hosting.)