RewriteRule doesn't work when requested path contains spaces

Hi,

I’m experiencing an issue with rewrite rules that didn’t happen before.

The following rule definitely used to work on InfinityFree, but I couldn’t tell you precisely when they broke. The website that used those had been sitting idle for a long while; the last time I know for sure this rule has been used at all was the beginning of last February.

I have found a similar issue that dates from May. It puts the blame on a bug in Apache 2.4.56 specifically:

A workaround I have confirmed worked here on infinityfree is to give the [B] flag to the rewriterule. [source]

Issue description

At the root of htdocs, I have the following .htaccess file:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*file)$ "/script.php?path=$1" [QSA]

The intended behaviour is: If the requested file doesn’t exist, and the path ends in “file”, run the given script.

In most cases, this will work properly. However, if the file doesn’t exist AND the path contains a space, then I am instead served with infinityfree’s stock 403 error.

Website URL

This is a minimal reproduction setup. There is nothing here except for the php script, the root .htaccess, and two text files.

Working as expected: (files are served)

Working as expected: (script runs)

Expected 404 error: (Path doesn’t match the rule’s regex, file doesn’t exist)

Unexpected 403 error: (Script should run)

Error Message

403 Forbidden

Server or website configuration is blocking you from viewing this page

1 Like

it should be like linux backslash space as far as im aware

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.