Recently found in the work of a strange syntax, Apache server site rewrite configuration file, began to think it is Apache a new syntax, to the word online search, did not search related articles, with old colleagues consulted, said this is Rewritemap, Did not know this directive before, today deliberately online check the next, found good, reference address: https://httpd.apache.org/docs/current/rewrite/rewritemap.html,/http blog.csdn.net/phphot/article/details/4049242 finishing as follows
Instructions are described below
According to the instructions, we know that this directive is equivalent to defining an extensible method for Rewritecond and Rewriterule, which implements a function similar to substitution (passing in a string, returning a string, or an empty sequence).
The syntax for defining an extension method is
Rewritemap MapName maptype:MapSource
Mapname is the method name, can be any string (avoid using the server reserved word, there should be a problem)
Maptype is the type of method and the optional type has TXT,RND,DBM,INT,PRG,DBD,FASTDBD
Mapsource is the execution method under different types, like the method body of a function in a programming language, which is understood for the time being, and is described in detail later
Use of extension methods
${MapName : LookupKey}
${MapName : LookupKey | DefaultValue}
Mapname method name when defining an extension method
LookupKey is the parameter of the incoming method
DefaultValue is the default value, and if the method returns an empty string, the default value is returned
Method type brief information is as follows
TXT text type
If the method type is txt, then Mapsource is a text file, and the content of the file file is a key-value pair with a space divider for each line, which can have comments and comments starting with #. The queried key-value pair is httpd cached unless the server restarts or the Mapsource text file modifies the change time
Rnd Text type extension (random)
If the method type is RND, similar to the TXT type, there can be multiple values in the key-value pairs in the text file, separated by |, and then randomly returned to a value after the key is
int internal method
If the method type is int, indicates the use of internal methods, case conversion, encoding of special characters, decoding of special characters
dbm dbm Hash file
If the method type is dbm, it indicates that using a hash file differs from a text file in that it is indexed, more efficient, and also supports the key that the cache queries to. The hash file used can be generated by a text file via the HTTXT2DBM tool, and the generated hash file hassdbm,gdbm,ndbm,db四种类型
DBD or FASTDBD
If the method type is DBD or FASTDBD, the use of SQL queries is indicated. Use of this type requires that the database module (MOD_DBD) be configured correctly. The SQL query may return more than one row, and if it is multiple rows, a row is used randomly. The difference between DBD and FASTDBD is that each request to the DBD queries the database, and FASTDBD caches the database query, unless the server restarts. FASTDBD more efficient and faster
PRG Custom Script
If the method type is PRG, indicating that the value of the incoming script is received through stdin using custom script processing, the returned value is returned by stdout
The working scenario is a URL of 301 jumps, via dbm
Configured as follows
Rewritemap map_301 dbm=db:/xxx/rewrite_mapping_301.db
Rewritecond ${map_301:%{request_uri}}!^$
Rewriterule ^/(. *) ${map_301:%{request_uri}} [qsa,r=301]
The original text file is similar
/test-brandstore//test-fashionfriends/
/test-nature-me//test-douglas/
/test-reifenchef//test-fritzreifen/
/test-personalgifts//test-yoursurprise/
/test-entertain//test-telekom/
/test-posterjack//test-posterxxl/
/test-d-living//test-mytime/
/test-klick//test-whitewall/
/test-myprinting//test-snapfish/
/test-papershaker//test-photobox/
/test-getmobile//test-sparhandy/
/test-parfumidee//test-geschenkidee-ch/
/test-ebookers-at//test-expedia-at/
/test-rs-components//test-rs-online/
/test-jack-und-jones//test-jack-and-jones/
/test-nded//test-nded-de/
/test-surfstitch//test-surfdome/
/test-hochzeitsgeschenke//test-geschenke24/
/test-baby-butt//test-kinderbutt/
/test-parfumdeal//test-yatego/
/test-gimahhot//test-yatego/
Finally put a httxt2dbm tool to use the method, easy to consult
Rewritemap (Apache)