Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Silambarasan's avatar

Space in URL returns 403 Forbidden error

I have the rest API

GET: https://my-url.com/users/{filter}/search

Example:

https://my-url.com/users/Test Value/search

It returns 403 forbidden error

But it works fine, if I have only one word as the search string, like:

Example: https://my-url.com/users/Test/search

Can you help me reg this?

0 likes
3 replies
LaryAI's avatar
Level 58

The issue is likely caused by the space in the URL. One solution is to encode the space as "%20" in the URL. So, instead of using "Value/search", use "Value%20/search".

Another solution is to modify the server configuration to allow spaces in URLs. This can be done by adding the following line to the .htaccess file:

AllowEncodedSlashes On

This will allow encoded slashes in URLs, including spaces.

If using nginx, the following configuration can be added to the server block:

server {
    ...
    merge_slashes off;
    ...
}

This will allow encoded slashes in URLs, including spaces.

Snapey's avatar

spaces in url are a bad idea. You should url encode the string before sending to catch other symbols as well as the space

Please or to participate in this conversation.