How to force www and not break the panel

Hi,

the following part in my .htaccess is forcing the www and https — pretty basic stuff.

# force www
RewriteCond %{HTTP_HOST} !=""
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# force https
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

But now when I try to access the panel I get this error message:

The panel cannot connect to the API

In the console I can see the following message:

Access to fetch at ‘https://mydomain.com/api/system?view=panel’ from origin ‘https://www.mydomain.com’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: Redirect is not allowed for a preflight request.

So I guess it’s because the API is trying to access the non-www domain, thereby triggering this CORS error. I just don’t know how to solve this properly.

Cheers
Robert

Try setting the URL in your config: https://getkirby.com/docs/reference/system/options/url

Perfect! Thanks :heart: