Mod_rewrite send anything that does not match rewriting

I have a htaccess file that starts with the usual stuff:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

i.e. a few rewrites, for example:

RewriteRule ^protect/?$ /Legal/Your-Financial-Protection.aspx   [NC, L, R=301]

then overwriting ends:

RewriteMap map txt:rewritemaps/map.txt  [NC]
RewriteRule ^(.+)$  ${map:$1}   [R=301]

The rewritemap contains all of our legacy URLs on our current site and short URLs that will be redirected to equivalent pages on the new site (about 4,000, so I really need to use a map):

Inspiration.aspx /Inspiration.aspx
Destinations/Africa/Countries/Gabon.aspx /Destinations/Africa/Gabon.aspx
indonesia /Destinations/Southeast-Asia/Indonesia.aspx

The problem is that with rewritemap turned on (i.e. not commented out) all my URLs (even those that don't match) are redirected to / - including stylesheets, js, images, etc.

What I need is a uris that matches the pattern on the map to redirect to a replacement and go through everything else (i.e. stay the same).

$1 :

RewriteRule ^(.+)$  ${map:$1|$1}    [R=301]

. , .css,.js,.jpg .., .

FYI, ISAPIRewrite HeliconTech ( IIS 6), , rewritemaps apache, .

!

,

+3
4

, . .

, :

RewriteCond ${map:$1} ^/.+
RewriteRule ^(.+)$ %0 [R=301]
+1

:

RewriteMap map txt:rewritemaps/map.txt  [NC]

RewriteMap .htaccess. (. RewriteMap) , .htaccess. , , .

+2

Gumbo , , URL . http://www.webmasterworld.com/apache/3830228.htm , , :

  RewriteCond ${moved:${escape:$1}} ^/.+
  RewriteRule ^(.+)$ %0 [R=301]

. , mod_rewrite

  IPADDR - - [07/Jan/2010:01:44:58 --0500] [example.org/sid#842a5a8][rid#100e0a18/initial] (2) init rewrite engine with requested uri /press/Partners With City.pdf
  IPADDR - - [07/Jan/2010:01:44:58 --0500] [example.org/sid#842a5a8][rid#100e0a18/initial] (3) applying pattern '^(.+)$' to uri '/press/Partners With City.pdf'
  IPADDR - - [07/Jan/2010:01:44:58 --0500] [example.org/sid#842a5a8][rid#100e0a18/initial] (5) map lookup OK: map=escape key=/press/Partners With City.pdf -> val=/press/Partners%20With%20City.pdf
  IPADDR - - [07/Jan/2010:01:44:58 --0500] [example.org/sid#842a5a8][rid#100e0a18/initial] (6) cache lookup FAILED, forcing new map lookup
  IPADDR - - [07/Jan/2010:01:44:58 --0500] [example.org/sid#842a5a8][rid#100e0a18/initial] (5) map lookup FAILED: map=moved[txt] key=/press/Partners%20With%20City.pdf
  IPADDR - - [07/Jan/2010:01:44:58 --0500] [example.org/sid#842a5a8][rid#100e0a18/initial] (4) RewriteCond: input='' pattern='^/.+' => not-matched
+1

adam, Gumbo , .

RewriteLogLevel 9 , .

+1

Source: https://habr.com/ru/post/1725762/


All Articles