Am buyildiung an angular2 application and hosted the php backend on a shared hosting. Whenever i send a post request am getting an error of
No 'Access-Control-Allow-Origin' header is present on the requested resource
In my local xampp i had to enable headers_module in the apache to resolve this, Ive contacted the shared hosting company but they cant enable the module
How can i go around this probably in the .htaccess file
This is current .htaccess file
RewriteEngine on
# hide files and folders
RedirectMatch 404 /_protected
RedirectMatch 404 /\.git
RedirectMatch 404 /composer\.
RedirectMatch 404 /.bowerrc
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "Content-Type"
What do i need to add in the above .htaccess file to act as a go around for this error, or even as a bypass for the
headers_module
No, you cannot use .htaccess
to load a module. The LoadModule directive context is:
server config, virtual host
But you don't need to rely on the server configuration, PHP can generate HTTP headers just fine:
header('Access-Control-Allow-Origin: *');
Of course, Yii has a builtin mechanism to generate HTTP headers.