Rewrite rule if condition is not matched

ApacheMod Rewrite

Apache Problem Overview


How may I perform a rule if the URL is NOT matching the path "forums"?

For example:

RewriteCond IF URL IS NOT forums
RewriteRule !\.(js|gif|css|jpg|png)$ %{DOCUMENT_ROOT}/index.php [L]

Apache Solutions


Solution 1 - Apache

Apache's RewriteCond as well as the RewriteRule directive support the exclamation mark to specify a non-matching pattern:

> You can prefix the pattern string with > a '!' character (exclamation mark) to > specify a non-matching pattern.

This should work:

RewriteCond %{REQUEST_URI} !^/forums.*
RewriteRule !\.(js|gif|css|jpg|png)$ /index.php [L]

--> redirect all requests not beginning with forums and not ending with the listed suffices to index.php

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjcoahdView Question on Stackoverflow
Solution 1 - ApachemarapetView Answer on Stackoverflow