I am attempting to prevent, within this situation WordPress, from spinning certain Web addresses. Within this situation I am attempting to prevent it from ever getting through a request within the uploads directory, and rather leave individuals towards the server's 404 page. So I am presuming it's as easy as adding the rule:

RewriteCond %{REQUEST_URI} !^/wp-content/uploads/

This rule should evaluate to false making the chain of rules fail for individuals demands, thus preventing the rewrite. But no... Possibly I have to match the coverage the entire string during my expression?

RewriteCond %{REQUEST_URI} !^/wp-content/uploads/.*$

Not a chance, that isn't it either. So after itching my mind I perform a check of sanity. Possibly something is wrong using the actual pattern. And So I create a simple test situation.

RewriteCond %{REQUEST_URI} ^/xyz/$

Within this situation, the rewrite happens if and only when the asked for URL is /abc/ and shows the server's 404 page for just about any other page. This is just what I was expecting. So I'll just stick inside a ! to negate that pattern.

RewriteCond %{REQUEST_URI} !^/xyz/$

Now I am looking to begin to see the complete opposite of the aforementioned condition. The rewrite shouldn't happen for /abc/ however for almost every other possible URL. Rather, the rewrite happens for each URL, both /abc/ yet others.

So, either using negated regexes in RewriteConds is damaged in Apache, or there is something fundamental I do not understand about this. Which could it be?

The server is Apache2.

The file in the whole:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /
RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/wp-content/uploads/
RewriteRule . /index.php [L]
</IfModule>

WordPress's default file plus my rule.

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /
RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_URI} !^/wp-content/uploads/ [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]
</IfModule>

If /wp-content/uploads/ is usually the prefix from the asked for URI path, your rule was designed to act as expected.

But because it clearly doesn’t work, do not match the road prefix from the full URI path only the rest of the path with no contextual per-directory path prefix, just in case from the .htaccess file within the document root directory the URI path with no leading /:

RewriteCond $0 !^wp-content/uploads/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .+ /index.php [L]

In the event that doesn’t work neither, it might certainly assistance to acquire some understanding of mod_rewrite’s spinning process by utilizing its logging feature. So set RewriteLogLevel to an amount with a minimum of 4, build your request and have a look in the records within the log file specified with [cde]. There you can observe how mod_rewrite handles your request with RewriteLog greater or comparable to 4 additionally, you will begin to see the values of variables like RewriteLogLevel.