简体   繁体   中英

Htaccess - Redirect domain.com to www.domain.com, BUT for different top level domains

A website of mine is accessible through different URL:

studienbuch.ch
studienbuch.at
studienbuch.com

I'd like to have them changed to www.studienbuch.tld, but keep the top level domain:

studienbuch.ch -> www.studienbuch.ch
studienbuch.at -> www.studienbuch.at
studienbuch.com -> www.studienbuch.com

How to handle that with .htaccess?

The following should work (untested):

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.studienbuch\.(ch|at|com)
RewriteRule ^(.*)$ http://www.studienbuch.%1/$1 [R=301,L]

Try

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

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