将非 WWW 重定向到 www [英] Redirect Non-WWW to www

查看:38
本文介绍了将非 WWW 重定向到 www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器上大约有 10 个域

i have about 10 domains on my server

site1.com
site2.com
site3.com

我想将 non-www 重定向到 www

site1.comwww.site1.com

site2.comwww.site2.com

我应该为每个站点添加 htaccess 吗?

Should i add htaccess for each site?

我可以在 apache 配置中缩短这份工作吗?

can i short this job in apache config?

推荐答案

Apache 配置中每个域的以下条目可以解决问题.请注意,您应该执行 301(永久)重定向,以确保搜索引擎理解您的 www 地址是规范地址.

The following entry in your Apache configuration for each domain would do the trick. Note that you should be doing a 301 (permanent) redirect to make sure the search engines understand that your www address is the canonical one.

<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com

Redirect 301 / http://www.example.com
</VirtualHost>

这篇关于将非 WWW 重定向到 www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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