简体   繁体   中英

htaccess redirect domain.com to www.domain.com except of staging.domain.com for multiple domains

I'm using the following htaccess do redirect people who not have the "www" or "staging" subdomain in the url to the www.domain.com subdomain

    RewriteCond %{HTTP_HOST} !^(www.domain.com|staging.domain.com)$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

Now I'd like to have the same generic for multiple domains. However the following isn't working:

    RewriteCond %{HTTP_HOST} !^((www|staging|dev).(^\.*).(de|lo))$ [NC]
    RewriteRule ^(.*)$ http://www.$2.de/$4 [L,R=301]

Returns in an configuration error.

Thx I appreciate your help!

Try this instead:

RewriteCond %{HTTP_HOST} !^(www|staging|dev)
RewriteCond %{HTTP_HOST} ^([^\.]+\.)?([^\.]+)\.(de|lo)$ [NC]
RewriteRule ^/(.*)$ http://www.%2.de/$1 [L,R=301]

%2 will match ([^\\.]+) from the RewriteCond, which will match any character that isn't a . between !(www|staging|dev). and .(de|lo)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM