没有`www`域就不能工作 [英] Domain doesn't work without `www`

查看:23
本文介绍了没有`www`域就不能工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在没有www(如http://example.com)的情况下输入我的域名时,它不起作用并给出错误消息.但是,当我向其中添加 www 时(如 http://www.example.com),它可以工作.

When I type in my domain name like without the www (like http://example.com), it doesn't work and gives error message. However, when I add the www to it (like http://www.example.com), it works.

它不是应该双向工作吗(有和没有 www)?

Isn't it supposed to work both ways (with and without the www)?

推荐答案

您只需要将以下代码添加到您的根 .htaccess 文件中:

All you need is to add the following code to your root .htaccess file:

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

这篇关于没有`www`域就不能工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆