apache redirect from non www to www

前端 未结 24 1343
春和景丽
春和景丽 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:12

    I ran this...

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

    I need this to be universal for 25+ domains on our new server, so this directive is in my virtual.conf file in a tag. (dir is parent to all docroots)

    I had to do a bit of a hack on the rewrite rule though, as the full docroot was being carried through on the pattern match, despite what http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html says about it only being stuff after the host and port.

提交回复
热议问题