From: Christophe Jaillet This document supplements the mod_rewrite should be considered a last resort, when other
+ mod_rewrite
reference documentation. It describes
-perhaps one of the most important concepts about mod_rewrite - namely,
+perhaps one of the most important concepts about mod_rewrite - namely,
when to avoid using it.mod_rewrite should be considered a last resort, when other
alternatives are found wanting. Using it when there are simpler
alternatives leads to configurations which are confusing, fragile, and
hard to maintain. Understanding what other alternatives are available is
-a very important step towards mod_rewrite mastery.mod_rewrite mastery.
Note that many of these examples won't work unchanged in your particular server configuration, so it's important that you understand @@ -99,12 +99,12 @@ following:
<VirtualHost *:80>
ServerName www.example.com
Redirect "/" "https://www.example.com/"
-</VirtualHost >
+</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
# ... SSL configuration goes here
-</VirtualHost >
+</VirtualHost>
The use of RewriteRule to perform this task may be
@@ -125,15 +125,15 @@ task in a .htaccess file instead.
The Alias directive
provides mapping from a URI to a directory - usually a directory outside
of your DocumentRoot. Although it
-is possible to perform this mapping with mod_rewrite,
-Alias is the preferred method, for reasons of simplicity
-and performance.
mod_rewrite,
+Alias is the preferred method, for
+reasons of simplicity and performance.
Alias "/cats" "/var/www/virtualhosts/felines/htdocs"
-The use of mod_rewrite to perform this mapping may be
+The use of mod_rewrite to perform this mapping may be
appropriate when you do not have access to the server configuration
files. Alias may only be used in server or virtualhost context, and not
in a .htaccess file.
@@ -147,7 +147,8 @@ server.
Although it is possible to handle virtual hosts
with mod_rewrite, it is seldom the right way. Creating individual
-<VirtualHost> blocks is almost always the right way to go. In the
+<VirtualHost> blocks is
+almost always the right way to go. In the
event that you have an enormous number of virtual hosts, consider using
mod_vhost_alias to create these hosts automatically.
RewriteRule provides the [P] flag to pass rewritten URIs through
+
RewriteRule provides the [P] flag to pass rewritten URIs through
mod_proxy.
RewriteRule "^/?images(.*)" "http://imageserver.local/images$1" [P]@@ -218,7 +219,8 @@ header, response header, or environment variable, replacing
See especially the expression evaluation documentation for a overview of what types of expressions you can -use in <If> sections, and in certain other directives.
+use in<If> sections,
+and in certain other directives.