I’ve already tried enabling CORS with the <Header Set Access-Control-Allow-Origin “*”> entry in the .htaccess
file, but it doesn’t work.
Whenever I want to test it with this page cors-test.codehappy.dev I get the message:
I’ve already tried enabling CORS with the <Header Set Access-Control-Allow-Origin “*”> entry in the .htaccess
file, but it doesn’t work.
Whenever I want to test it with this page cors-test.codehappy.dev I get the message:
I already found the solution, but I still want to share it. You have to edit the vhost.conf
.
→ see list of vhosts
cd /usr/local/lsws/conf/vhosts/
la -la
→ go to your Domain
cd yourdomain.xyz
la -la
→ do a backup
cp vhost.conf vhost.conf.bak
→ edit vhost.conf
nano vhost.conf
→ add the following
context / {
location $DOC_ROOT/
allowBrowse 1
extraHeaders Access-Control-Allow-Origin *
rewrite {
RewriteFile .htaccess
}
addDefaultCharset off
phpIniOverride {
}
}
→ restart LiteSpeed Web Server
systemctl restart lsws
Now it should work and you will see:
Addendum: If you only want CORS to be activated for a certain directory, then you can specify the path that should be allowed in vhost.conf
after context /
. Here e.g. the path /public_html/.well-known`.
context /public_html/.well-known {
location $DOC_ROOT/
allowBrowse 1
extraHeaders Access-Control-Allow-Origin *
..