apache redirect from non www to www

前端 未结 24 1382
春和景丽
春和景丽 2020-11-22 06:34

I have a website that doesn\'t seem to redirect from non-www to www.

My Apache configuration is as follows:

RewriteEngine On
### re-direct t         


        
24条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 07:17

    I had a similar task on a WP Multisite, where the redirection rule had to be generic (for any given domain I'd add to the network). I solved first adding a wildcard to the domain (parked domain). Note the . after .com.

    CNAME * domain.com.
    

    And then I added the following lines to the .htaccess file at the root of my multisite. I guess it'd work for any site.

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

    Hopefully this will help.

    ps. If you'd like to redirect from not www to www, change the last line into

    RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
    

提交回复
热议问题