Redirecting URL without www to www

◇◆丶佛笑我妖孽 提交于 2019-11-29 10:08:42

问题


I need your help. I want to test if the URL is entered without www

like example.com it should be forwarded to www.example.com.


回答1:


Try this mod_rewrite rule:

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



回答2:


RewriteEngine On

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



回答3:


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;
}


来源:https://stackoverflow.com/questions/2272159/redirecting-url-without-www-to-www

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