Redirecting URL without www to www

≯℡__Kan透↙ 提交于 2019-11-30 07:33:08

Try this mod_rewrite rule:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteEngine On

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^.*$ http://www.example.com/$0 [NC,L,R=301]

If you are using nginx, then add this line to nginx config:

server {
  listen 80;
  server_name yourdomain.com;
  rewrite ^/(.*) http://www.yourdomain.com/$1 permanent;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!