Damiano Barbati
Damiano Barbati

Reputation: 3496

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.

Upvotes: 1

Views: 474

Answers (1)

anubhava
anubhava

Reputation: 785098

You can use regex alternation. So for your given example you can use:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?domain\.(com|es)$
RewriteRule ^wp-admin https://secure.domain.%1/wp-admin/ [R=301,L,NC]

Upvotes: 2

Related Questions