No access-control-allow-origin header is present on the requested resource php

WordPress No 'Access-Control-Allow-Origin' header is present on the requested resource

I am pulling posts from one WordPress website to another. Both websites are on same server. For pulling posts i am using jQuery.ajax with Rest API. But i am getting error message in console

Access to XMLHttpRequest at 'https://www.website1.com/wp-json/wp/v2/posts/?tags=4,198&per_page=24&offset=1&_embed' from origin 'https://website2.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

For this i have added following header

Header set Access-Control-Allow-Origin "*"

In .htaccess of both websites. Also i have used this

crossDomain: true,

In ajax. But still having error. Any help. Please

Solutions

Just add below lines to .htaccess file and we should be good.

<ifmodule mod_headers.c=""> SetEnvIf Origin "^(.*\.domain\.com)$" ORIGIN_SUB_DOMAIN=$1 Header set Access-Control-Allow-Origin "%{ORIGIN_SUB_DOMAIN}e" env=ORIGIN_SUB_DOMAIN Header set Access-Control-Allow-Methods: "*" Header set Access-Control-Allow-Headers: "Origin, X-Requested-With, Content-Type, Accept, Authorization" </ifmodule>

Similar questions

AngularJS XMLHttpRequest cannot load X. No 'Access-Control-Allow-Origin' header present

I've just seen the entire internet, and I can't seem to find a solution to my problem. I'm working on my new portfolio website, which can be found on http://geertvandelangenberg.nl/angular. I'm currently fetching my content through a Wordpress API, and I'm parsing with AngularJS' $http. Everything works good on pretty much all places I check, excep...

Also ask

Last updated 3 months ago.

HI, I normally add this on the app/filter.php file

App::before(function($request) { header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, POST, OPTIONS'); header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With'); header('Access-Control-Allow-Credentials: true'); });

Last updated 3 months ago.

Thaknks wing-dev it really saved me :)

Last updated 3 months ago.

Thanks a lot wing-dev!!

Last updated 3 months ago.

Just dropping by to say thanks, also. I tried adding the headers via a 'cors' filter and applying the 'cors' filter both before and after route. It did not work. But this suggestion did.

Hi, Create a Cors middleware and register it in the application's global HTTP middleware stack in kernel.php. Follow this for more.

Last updated 4 years ago.

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

Laravel.io

The community

© 2022 Laravel.io - All rights reserved.

Skip to content

Support » Fixing WordPress » CORS policy No Access-Control-Allow-Origin header is present on request resource

  • Hi

    https://www.lingvopedia.com/professional-translation-services/

    When I submit the form in this page i got error that related to cors policy

    ERROR:
    1.Access to XMLHttpRequest at ‘https://lingvo.bitrix24.in/pub/form/42_leads_services_forms/g4w8pt/?form_code=42_leads_services_forms&sec=g4w8pt&#8217; from origin ‘https://www.lingvopedia.com‘ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

    2.POST https://lingvo.bitrix24.in/pub/form/42_leads_services_forms/g4w8pt/?form_code=42_leads_services_forms&sec=g4w8pt net::ERR_FAILED

    And I have tried to fix this adding code to enable Access-Control-Allow-Origin via header.php,htaccess file, functions. php and also tried to fix by installing Http Headers plugin and Wp-cors plugins But Nothing work So please advice how to resolve this issue

    • This topic was modified 1 year, 1 month ago by suruthiv.

    The page I need help with: [log in to see the link]

  • The topic ‘CORS policy No Access-Control-Allow-Origin header is present on request resource’ is closed to new replies.

How do you solve no Access

There Are Two Approaches to Getting It Right. Use a reverse proxy server or WSGI server(such as Nginx or Apache) to proxy requests to your resource and handle the OPTIONS method in the proxy. Add support for handling the OPTIONS method in the resource's code.

How do you fix origin is not allowed by Access

In that case you can change the security policy in your Google Chrome browser to allow Access-Control-Allow-Origin. This is very simple: Create a Chrome browser shortcut. Right click short cut icon -> Properties -> Shortcut -> Target.

What is Access

You can add the origin of the request to the list of domains authorized to access the server's resources by adding it to the values of the Access-Control-Allow-Origin header. You can set it via the header() function of PHP (https://www.php.net/manual/fr/function.header.php).

How do I add Access

For IIS6.
Open Internet Information Service (IIS) Manager..
Right click the site you want to enable CORS for and go to Properties..
Change to the HTTP Headers tab..
In the Custom HTTP headers section, click Add..
Enter Access-Control-Allow-Origin as the header name..
Enter * as the header value..
Click Ok twice..