Search code examples
apachemod-rewrite

Apache RewriteMap syntax for full URLs


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

http://www.example.com/some-random-url http://www.example.net/some-random-url

For each entry the source domain, eg. example.com above, is the same, but the destination domain, example.net 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.


Solution

  • 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}}