Reputation: 1763
I have a need match part of a domain name with a regex and redirect to a different domain with the matched part being part of the filename.
Example, in the htaccess on this-is.com:
this-is-a-test.com redirects to this-is.com/test.htm
this-is-a-fish.com redirects to this-is.com/fish.htm
this-is-a-duck.com redirect to this-is.com/duck.htm
So far I have tried the following:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^this-is-a-(.*).com$
RewriteRule (.*) http://this-is.com/test.htm [L]
But that doesn't work as the RewriteRule only handles the querystring portion and not the host part.
How do I use the matched part of the RewriteCond in the RewriteRule ?
Upvotes: 2
Views: 2396
Reputation: 1763
Solved it!
For future reference, you should use the percentage sign for the RewriteCond Match:
RewriteCond %{HTTP_HOST} ^this-is-a-(.*).com$
RewriteRule (.*) http://this-is.com/%1.htm [L]
Upvotes: 2