Code Bytes
Keep one static directory outside a CMS's Apache rewrites
A precise Apache rewrite exception for a standalone directory, with path-boundary matching and a clear distinction from redirects and access control.
Sometimes a small static section should live beside a CMS without passing through its front controller. That is an internal routing exception, not a redirect: the browser's URL stays the same.
Make the exception exact
For an Apache-hosted site, place this in the root .htaccess before the CMS's catch-all rewrite rules:
RewriteEngine On
RewriteRule ^competition(?:/|$) - [END]
This matches /competition and /competition/..., but not /competition-winners/. The - means “leave the path unchanged”. Apache 2.4's END stops subsequent per-directory rewrite processing for this request.
Create the actual competition/ directory and its index.html. Apache's normal directory handling supplies the slash redirect and index document, subject to your server configuration. A path that does not exist should still return 404—it should not become a CMS page accidentally.
Keep the scope small
Use this for a genuinely standalone static directory. END is not appropriate if that child application needs its own .htaccess rewriting; in that case, configure the child application's routing explicitly at the host or virtual-host level.
An exception does not make files private, disable PHP or protect backups. Keep source/configuration out of the public directory, disable directory listings where appropriate, and apply the normal access policy. Existing WordPress rules already bypass many real files and directories, so check whether an additional exception is needed before adding one.
Test the directory index, one asset, one missing file and a similar-but-unrelated CMS slug. This is Apache-specific; Nginx and Cloudflare need their own routing configuration.
References: Apache's END flag and per-directory rewriting.
Original version29 March 2014
Kept here for reference and earlier links. The updated guide above is the recommended starting point; older code may depend on retired services or different software versions.
More often than not you'll be using a CMS for your website, this CMS will control all traffic through set files usually (such as a root index file).
This creates a nice fluid system, where only a few files have to be changed to alter the whole website.
However, there are occasions when you want to have a certain directory to be completely different in design/feel/content etc.
The CMS .htaccess by default will try and route all requests through its normal setup.
Example: You have your amazing pet dog blog on a CMS. But you want to create a special page called myPetDogs.com/competition/ which is completely separate from the rest of your site/blog.
Your CMS will currently try to relay that directory ("/competition/") to some content, usually resulting in a 404.
This is easily achieved by bypassing the CMS' default .htaccess rules by adding the following line before your CMS rewrite rules:
RewriteRule ^competition - [L,NC]
This is essentially just saying, if the directory is competition, do nothing and let it go to that directory and show the content there (usually an index.htm/php file).
Keep exploring