Adobe-Consulting-Services / acs-aem-commons

http://adobe-consulting-services.github.io/acs-aem-commons/
Apache License 2.0
451 stars 597 forks source link

if i want to make use of two rewrite maps. #2136

Closed viki8 closed 4 years ago

viki8 commented 4 years ago

Required Information

Expected Behavior

We have rewrites under two nodes: eg: /etc/acs-commons/redirect-maps/node1/jcr:content.redirectmap.txt /etc/acs-commons/redirect-maps/node2/jcr:content.redirectmap.txt

Used the script present, it generated files .dir and .pag for two nodes. I have to use two map files in my Apache configuration. I have tried below configuration only node1 rewrites are getting picked up.

rewrite rules

RewriteMap map.legacy dbm:/etc/httpd/conf/node1.map RewriteMap map.legacy dbm:/etc/httpd/conf/node2.map RewriteCond ${map.legacy:$1} !="" RewriteRule ^(.*)$ ${map.legacy:$1|/} [L,R=301]

Tried to create two separate files and included then in VHOST configuration. this one dindn't work to.

rewrite rules

RewriteMap node1map.legacy dbm:/etc/httpd/conf/node1.map RewriteCond ${map.legacy:$1} !="" RewriteRule ^(.*)$ ${map.legacy:$1|/} [L,R=301]

rewrite rules

RewriteMap node2map.legacy dbm:/etc/httpd/conf/node2.map RewriteCond ${map.legacy:$1} !="" RewriteRule ^(.*)$ ${map.legacy:$1|/} [L,R=301]

Actual Behavior

URL's are not getting redirected.

Steps to Reproduce

create a two map files and try to include it in the Apache configuration only one file gets loaded.

Links

Links to related assets, e.g. content packages containing test components

joerghoh commented 4 years ago

For that case you don't need any extension to the RewriteMap feature, because it already supports storing the rewrites in multiple nodes. You just need to do the scripting right.

In the cron script the the definition of "MAPS" should look like this:

     MAPS=(
         "node1"
         "node2"
     )

Then everything would work fine.

viki8 commented 4 years ago

Hello @joerghoh,

please elaborate this "you just need to do the scripting right"

++ if I create two nodes, the script will create two txt files, node1.txt and node2.txt. now should I merge both the node files at script level and then create a index of this so that it would create a one .dir and .pag file? ++

Do you have any example configuration for reference.

Thanks, Viki

joerghoh commented 4 years ago

This is the customized version of the cron script at https://adobe-consulting-services.github.io/acs-aem-commons/features/redirect-map-manager/index.html

The major changes are within the loop; I download all map files and concatenate it into a single file, which is converted into a single pair of .dir and .pag files. This can be included into the httpd configuration as documented (make sure that the filenames match).

     #!/bin/bash

     # Configuration values
     PUBLISHER_IP=127.0.0.1
     LOG_DIR=/var/log/httpd
     MAPS=(
         "site-vanities"
         "site-legacy-redirects"
     )

     # Update the redirect maps
     CONSOLIDATED=/tmp/redirects.txt
     for MAP_FILE in "${MAPS[@]}"
     do
                     :
         wget http://${PUBLISHER_IP}:4503/etc/acs-commons/redirect-maps/${MAP_FILE}/jcr:content.redirectmap.txt -O /tmp/${MAP_FILE}.txt >> ${LOG_DIR}/update-redirect-map.log 2>&1
         cat /tmp/${MAP_FILE}.txt  >> ${CONSOLIDATED}
     done
     httxt2dbm -i ${CONSOLIDATED} -o /etc/httpd/conf/tmp.map >> ${LOG_DIR}/update-redirect-map.log 2>&1
     mv /etc/httpd/conf/tmp.map.dir /etc/httpd/conf/${MAP_FILE}.map.dir
     mv /etc/httpd/conf/tmp.map.pag /etc/httpd/conf/${MAP_FILE}.map.pag
viki8 commented 4 years ago

Hi @joerghoh,

I should have asked this question before, after all this now i understood is more that one map file is not supported, we need to merge all the files into one and create an index.

++++ Thanks for your inputs, I had the same opinion here and implemented it.

one input here is use : paste -d "\n" /tmp/${MAP_FILE}.txt >> ${CONSOLIDATED} instead of: cat /tmp/${MAP_FILE}.txt >> ${CONSOLIDATED} ++++

joerghoh commented 4 years ago

@viki8 were you able to solve your problem?

viki8 commented 4 years ago

@joerghoh, With merging two files into one has solved my problem.

Thanks,