the_real_pelican the_real_pelican - 1 year ago 106
Apache Configuration Question

Apache RewriteMap syntax for full URLs

I have a rewrite map with around 5000 entries like this:

For each entry the source domain, eg above, is the same, but the destination domain, above, is a different domain. The path pattern also changes with each URL (I wish I could post more than 2 links!)

What I have so far is:

RewriteEngine On

RewriteMap examplemap "txt:/etc/httpd/conf/redirect.txt"

RewriteCond ${examplemap:$1} !=""

RewriteRule ^/(.*) ${examplemap:$1} [redirect=permanent,last]

I cannot seem to get the correct syntax for the RewriteCond and RewriteRule directives and would be grateful for any help, thanks.

Answer Source

If I understand correctly, you want the key of the rewrite map to be the current URL and then find the matching redirect.

Then you can use :

RewriteRule .* ${examplemap:http://%{HTTP_HOST}%{REQUEST_URI}}