Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Fix: %20 in URL Causes 403 Forbidden Error

Fix: %20 in URL Causes 403 Forbidden Error

If you encounter a 403 Forbidden error when trying to access a URL with spaces encoded as %20, follow this guide for the solution.


🚨 Problem

Accessing URLs with spaces, such as example.com/index.php?query=two words, leads to encoding as example.com/index.php?query=two%20words, which may trigger a 403 Forbidden error and block access to the page.

🔍 Diagnostics

To confirm this issue, try using + instead of %20 in the URL:

  • URL with +: Accessing example.com/index.php?query=two+words should work correctly.
  • Testing Command:bashCopy codewget https://www.example.com/index.php?query=two%20words Output:arduinoCopy code--2024-06-27 16:27:21-- https://www.example.com/index.php?query=two%20words Resolving www.example.com (www.example.com)… 1234:f1c1:123f:f987::1f1, 12.123.234.123 Connecting to www.example.com (www.example.com)|1234:f1c1:123f:f987::1f1|:443… connected. HTTP request sent, awaiting response… 403 Forbidden 2024-06-27 16:27:21 ERROR 403: Forbidden.

đź›  Solution

The likely cause is the configuration of your .htaccess file.

  1. Open .htaccess File
    Locate the .htaccess file in your website’s root directory (commonly /public_html/ or /home). Open it using your preferred text editor.
  2. Modify the RewriteRule
    Find the line with RewriteRule, which should look similar to:apacheCopy codeRewriteRule (.*)$ /index.php?path=$1 [NC,QSA,L]
  3. Add the B Flag
    Update the line to include the B flag, which tells RewriteRule to escape special characters like %20:apacheCopy codeRewriteRule (.*)$ /index.php?path=$1 [B,NC,QSA,L]
  4. Save and Test
    After saving the .htaccess changes, reload the page using %20 in the URL. This should resolve the 403 Forbidden error.

For users looking to enhance their server capabilities, please review our VPS packages. For cloud backup options, please use the following link: cloud backup link.

Leave a Reply

Your email address will not be published. Required fields are marked *