Home  >  Article  >  Web Front-end  >  Why is Access from Origin \'https://example.com\' Blocked Even Though I\'ve Allowed \'https://example.com/\'?

Why is Access from Origin \'https://example.com\' Blocked Even Though I\'ve Allowed \'https://example.com/\'?

Linda Hamilton
Linda HamiltonOriginal
2024-11-01 13:26:02535browse

Why is Access from Origin 'https://example.com' Blocked Even Though I've Allowed 'https://example.com/'?

Access from Origin 'https://example.com' Has Been Blocked Even Though I've Allowed 'https://example.com/'

When attempting to access a resource cross-origin, developers often encounter issues related to the Access-Control-Allow-Origin header. The key to resolving these issues lies in understanding the precise meaning of "origin" in the context of the CORS protocol.

The Concept of Origin in CORS

In CORS, an origin is a combination of a scheme, host (domain), and port. Importantly, it does not include a path. Therefore, the following two origins are considered distinct:

  • https://example.com
  • https://example.com/path/to/resource

The Problem: Trailing Slashes in Origins

The problem in this particular case arises from a misunderstanding of the definition of origin. Specifically, the trailing slash in the allowed origin is not permitted according to CORS protocol specifications. As a result, the origin header sent by the browser (without the trailing slash) does not match the allowed origin configured on the server.

Solution: Remove Trailing Slash from Allowed Origin

To resolve this issue, simply remove the trailing slash from the allowed origin value in your CORS configuration. In this case, the correct allowed origin would be:

  • https://googledocs-clone-sbayrak.netlify.app

With this modification, the browser's origin header will match the allowed origin, and CORS will be allowed successfully.

The above is the detailed content of Why is Access from Origin \'https://example.com\' Blocked Even Though I\'ve Allowed \'https://example.com/\'?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn