1

I have a bunch of domains that I want to go to one domain but various parts of that domain.

# this is what I currently have
RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*\.?foo\.com$ [NC]
RewriteRule ^.*$ ${domainmappings:www.foo.com} [L,R=301]

# rewrite map file
www.foo.com www.domain.com/domain/foo.com.php
www.bar.com www.domain.com/domain/bar.com.php
www.baz.com www.domain.com/other/baz.php.foo

The problem is that I don't want to have to have each domain be part of the RewriteCond. I tried

RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule (.*) http://%1/$1 [R=301,L]

but that will do it for EVERY domain. I only want the domains that are in the mappings file to redirect, and then continue on to other rewrites if it doesn't match any domains in the mappings file.

scott
  • 11
  • 1

1 Answers1

0

You can deref the map in a condition and make sure it's non-empty, and then capture it so you aren't going back to the map twice:

RewriteCond ${domainmappings:%{HTTP_HOST}) (.+) RewriteRule .* %1 [L,R=301]

covener
  • 1,685
  • 9
  • 15