Logic Based Rewriting Syntax
Most of this has to do with retaining path prefixes (aka directories) through updates. For example, when everything has been from this sub-directory /blahblah/ to /barf/ versus /blah/blah/ to /blah/barf/.
Here's the categories:
- Same host, different path, retaining 1,2, or 3 path sub directories. These types of redirects are tagged with the rewrite type id of 1.1, 1.2, 1.3, or so-on, depending upon how many path prefixes anyone would normally deal with.
- Same host, different path, rewrite type id 2.
- Different host, same path, rewrite type is 3.
There are few parts to setting this up. First the host needs to be looked up and checked for each one of these "special" rewriting cases, like this in an Apache configuration:
RewriteCond ${redirects:_L,R=301_1.3_%{HTTP_HOST}} 1300
Explanation: the L,R=301 is basically just a prefix tag based upon modrewrite's flags. L for last, R=301 for permanent redirection. 1.3 is the redirect type id number. 1300 is the value the modrewrite is querying to discover if there are any types of these redirects for the host in question.
If there is a key for "L,R=3011.3_www.example.com" and the value is 1300, then rewrite logic will continue, and more detailed lookups will be made, along these lines:
RewriteCond ${redirects:_L,R=301_%{HTTP_HOST}} 1300
RewriteCond %{REQUEST_URI} ^/(\w+)/(\w+)/(.*)
RewriteCond ${redirects:_L,R=301_%{HTTP_HOST}/%1/%2|0} !^0$
RewriteRule ^/(\w+)/(\w+)/(.*) http://${redirects:_L,R=301_%{HTTP_HOST}/$1/$2}/$3 [L,R=301]