You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rb...@apache.org on 2026/05/02 19:32:26 UTC
svn commit: r1933712 - httpd/httpd/branches/2.4.x/docs/manual/rewrite
Author: rbowen
Date: Sat May 2 19:32:26 2026
New Revision: 1933712
Log:
rewrite guide: add FallbackResource and If-expression sections to avoid.xml (BZ 58892, step 10)
Modified:
httpd/httpd/branches/2.4.x/docs/manual/rewrite/avoid.xml
Modified: httpd/httpd/branches/2.4.x/docs/manual/rewrite/avoid.xml
==============================================================================
--- httpd/httpd/branches/2.4.x/docs/manual/rewrite/avoid.xml Sat May 2 19:31:33 2026 (r1933711)
+++ httpd/httpd/branches/2.4.x/docs/manual/rewrite/avoid.xml Sat May 2 19:32:26 2026 (r1933712)
@@ -240,6 +240,82 @@ and in certain other directives.</p>
</section>
+<section id="fallback-resource"><title>Front Controller / Resource Routing</title>
+
+<p>A very common use of <module>mod_rewrite</module> is to route all
+requests for non-existent resources to a single front controller script
+(e.g. <code>index.php</code>). This is the basis of most modern web
+framework routing.</p>
+
+<p>The typical <module>mod_rewrite</module> approach is:</p>
+
+<highlight language="config">
+RewriteEngine On
+RewriteCond "%{REQUEST_FILENAME}" !-f
+RewriteCond "%{REQUEST_FILENAME}" !-d
+RewriteRule "^(.*)$" "/index.php" [L]
+</highlight>
+
+<p>This can be accomplished far more simply with the
+<directive module="mod_dir">FallbackResource</directive> directive:</p>
+
+<highlight language="config">
+FallbackResource /index.php
+</highlight>
+
+<p><directive module="mod_dir">FallbackResource</directive> does the
+same thing - requests for existing files and directories are served
+normally, while everything else is routed to the specified resource -
+but without the overhead and complexity of the rewrite engine. It works
+in both server configuration and <code>.htaccess</code> context.</p>
+
+<p>To disable a <code>FallbackResource</code> set in a parent
+directory:</p>
+
+<highlight language="config">
+FallbackResource disabled
+</highlight>
+
+</section>
+
+<section id="ifexpr"><title>Conditional Configuration with Expressions</title>
+
+<p>Many uses of <directive module="mod_rewrite">RewriteCond</directive>
+can be replaced by the
+<directive module="core" type="section">If</directive> directive, which
+supports a rich <a href="../expr.html">expression syntax</a> and
+integrates cleanly with other Apache directives.</p>
+
+<p>Redirect based on a query string parameter:</p>
+
+<highlight language="config">
+<If "%{QUERY_STRING} =~ /lang=fr/">
+ Redirect "/welcome" "/bienvenue"
+</If>
+</highlight>
+
+<p>Restrict access by request method:</p>
+
+<highlight language="config">
+<If "%{REQUEST_METHOD} IN {'DELETE', 'PUT', 'PATCH'}">
+ Require ip 10.0.0.0/8
+</If>
+</highlight>
+
+<p>Block requests missing a Host header (HTTP/1.0 clients):</p>
+
+<highlight language="config">
+<If "-z req('Host')">
+ Require all denied
+</If>
+</highlight>
+
+<p>See the <a href="../expr.html">expression evaluation
+documentation</a> for the full syntax available in
+<directive module="core" type="section">If</directive> blocks.</p>
+
+</section>
+
<section id="blocked-inline-images">
<title>Forbidding Image Hotlinking</title>