htaccess to match subdomain in host variable

I’m running a multisite wordpress installation with 13+ sites.

www.domain.com
www.domain.es
www.domain.it
and so on...

I must redirect the wp-admin folders for each domain to https://secure.domain.tld

Examples:

http://www.domain.com/wp-admin => https://secure.domain.com/wp-admin
http://www.domain.es/wp-admin => https://secure.domain.es/wp-admin
http://www.domain.it/wp-admin => https://secure.domain.it/wp-admin

Right now I’m using:

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www.domain.com
RewriteRule ^wp-admin https://secure.domain.com/wp-admin/ [R=301,L]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www.domain.es
RewriteRule ^wp-admin https://secure.domain.es/wp-admin/ [R=301,L]

It works.
But it sucks.
Is there any clean solution to not repeat this for each domain? Is there any variable matching possibile with the host?

Thanks.


Source: .htaccess

Leave a Reply