htaccess - get all non-www traffic redirected to the www

南笙酒味 提交于 2019-12-22 08:54:35

问题


Can anyone suggest how I get non www traffic to redirect to the www version of a website using the htaccess file - I know I have one created in my root directory but cannot be sure what to put.. any ideas


回答1:


Relatively easily.

Match anything that does not begin with 'www.' and then redirect to the 'www.' version:

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


来源:https://stackoverflow.com/questions/9314520/htaccess-get-all-non-www-traffic-redirected-to-the-www

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!