I have recently updated a website to Craft 4 and all went well, but now I cannot login to the Control Panel as I'm getting an error:
Access to XMLHttpRequest at 'https://www.xxx.com/index.php?p=cplogin%2Factions%2Fusers%2Flogin&v=1666866059344' from origin 'https://xxx.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.
I have read various other posts and added in a combination of the following lines to the web/.htaccess file, but im really out of my depth with this error and don't really understand what to do as its not making any difference (i've added all lines in incase one of them is correct!):
<IfModule mod_rewrite.c>
RewriteEngine On
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]
</IfModule>
<ifModule mod_headers.c>
Header always set Access-Control-Allow-Headers "X-Requested-With, Authorization, Content-Type, Request-Method"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
SetEnvIf Origin "^http(s)?://(.+\.)?(xxx.com)(:[0-9]+)?$" origin_is=$0
Header always set Access-Control-Allow-Origin %{origin_is}e env=origin_is
SetEnvIf Origin ".*\S.*" ORIGIN=$0
Header always set Access-Control-Allow-Origin %{ORIGIN}e env=ORIGIN
</ifModule>
Obviously all references to 'xxx.com' have been changed from the live domain.