From: Rich Bowen Date: Mon, 11 May 2026 12:22:00 +0000 (+0000) Subject: Rewrite guide: deduplicate front-controller/FallbackResource content X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ed359048a814210a0ba0104853ff02cf7deb804b;p=thirdparty%2Fapache%2Fhttpd.git Rewrite guide: deduplicate front-controller/FallbackResource content remapping.xml had two sections (front-controller and fallback-resource) that duplicated the advice in avoid.xml. Replace front-controller with a brief cross-reference to avoid.xml and htaccess.xml; remove the fallback-resource section entirely (it also referenced pre-2.2.16 Apache, which is no longer relevant). Update htaccess.xml cross-reference link to point to avoid.html#fallback-resource (its canonical home). git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1934084 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/rewrite/TODO.md b/docs/manual/rewrite/TODO.md index 44189527db..55c75c55ad 100644 --- a/docs/manual/rewrite/TODO.md +++ b/docs/manual/rewrite/TODO.md @@ -14,7 +14,7 @@ result in one file "owning" the content and others cross-referencing it. (htaccess.xml, plus both the [L] and [END] sections of flags.xml). → htaccess.xml owns the full explanation; flags.xml slims down + xrefs. -- [ ] **FallbackResource / front-controller** recipe appears in four +- [x] **FallbackResource / front-controller** recipe appears in four places across three files (avoid.xml, remapping.xml ×2, htaccess.xml). → avoid.xml owns it; others cross-reference. diff --git a/docs/manual/rewrite/htaccess.xml b/docs/manual/rewrite/htaccess.xml index bd71c0e048..432bebfca9 100644 --- a/docs/manual/rewrite/htaccess.xml +++ b/docs/manual/rewrite/htaccess.xml @@ -162,7 +162,7 @@ RewriteRule "^(.*)$" "index.php" [L] For this particular use case - routing all unmatched requests to a front controller - the -FallbackResource directive +FallbackResource directive is a simpler and more efficient alternative to mod_rewrite.

Without the RewriteBase "/myapp/" line, the rewritten diff --git a/docs/manual/rewrite/remapping.xml b/docs/manual/rewrite/remapping.xml index 47b6aed9e5..daced54a5a 100644 --- a/docs/manual/rewrite/remapping.xml +++ b/docs/manual/rewrite/remapping.xml @@ -247,52 +247,19 @@ RewriteRule "^(.*)" "https://%1$1" [R=301,L] Front Controller / Application Routing -

-
Description:
- -
-

Most modern web frameworks (PHP, Python, Ruby, etc.) use a - single entry point - often called a "front controller" - that - handles all requests. URLs like /products/widget - are routed to index.php (or equivalent), which - parses the URL internally.

-
- -
Solution:
- -
- - For this use case, the - FallbackResource directive is - almost always the better choice. See the - Fallback Resource recipe above. - -

If you need mod_rewrite (for example, to add - additional conditions), the standard pattern is:

- - -RewriteEngine On -RewriteCond "%{REQUEST_FILENAME}" !-f -RewriteCond "%{REQUEST_FILENAME}" !-d -RewriteRule "^(.*)$" "/index.php" [L] - - -

The !-f and !-d conditions skip the - rule for requests that map to an existing file or directory, so - static assets (images, CSS, JavaScript) are still served - directly.

-
- -
Discussion:
- -
-

In .htaccess context, consider using - [END] instead of [L] to avoid - reprocessing loops. See the - .htaccess looping discussion - for details.

-
-
+

Most modern web frameworks route all requests through a single + entry point (a "front controller"). The + FallbackResource directive + handles this more simply and efficiently than + mod_rewrite. See When NOT to use mod_rewrite + for the recommended approach.

+ +

If you genuinely need mod_rewrite for this (for + example, to add conditions beyond "file doesn't exist"), see the + per-directory rewrites + document for an annotated example that also demonstrates + RewriteBase usage.

@@ -700,65 +667,6 @@ rather than rewriting URLs.

-
-Fallback Resource - -
-
Description:
-
You want a single resource (say, a certain file, like index.php) to -handle all requests that come to a particular directory, except those -that should go to an existing resource such as an image, or a css file.
- -
Solution:
-
-

As of version 2.2.16, you should use the FallbackResource directive for this:

- - -<Directory "/var/www/my_blog"> - FallbackResource index.php -</Directory> - - -

However, in earlier versions of Apache, or if your needs are more -complicated than this, you can use a variation of the following rewrite -set to accomplish the same thing:

- - -<Directory "/var/www/my_blog"> - RewriteBase "/my_blog" - - RewriteCond "/var/www/my_blog/%{REQUEST_FILENAME}" !-f - RewriteCond "/var/www/my_blog/%{REQUEST_FILENAME}" !-d - RewriteRule "^" "index.php" [PT] -</Directory> - - -

If, on the other hand, you wish to pass the requested URI as a query -string argument to index.php, you can replace that RewriteRule with:

- - -RewriteRule "(.*)" "index.php?$1" [PT,QSA] - - -

Note that these rulesets can be used in a .htaccess -file, as well as in a <Directory> block.

- -
- -
Discussion:
- -
-

The FallbackResource directive -is almost always the better choice for this use case. See the -When not to use mod_rewrite -document for a simpler one-line alternative.

-
- -
- -
-
Rewrite query string