把不带前缀的域名转向到www.域名的Apache 301转向配置样例
各种不同的域名地址对于搜索引擎的除重(deduplication)来说是一个负担,有没有"/“和首页的文件连接,一个域名首页就可以有6个地址: www.chedong.com/ chedong.com/ www.chedong.com chedong.com www.chedong.com/index.php chedong.com/index.php
如果加上一些参数,比如用于来源跟踪等还会有更多无穷无尽的地址。 www.chedong.com/?source=foobar
所以搜索引擎鼓励发布者把URL标准化(归一化)。首先就是域名的归一化,原先我的设置为: www.chedong.com / chedong.com为别名。现在改为chedong.com 301转向到www.chedong.com <VirtualHost :80> ServerName chedong.com RewriteEngine on RewriteRule ^(.)$ http://www.chedong.com$1 [R=301,L]
如果没有mod_rewrite也可以设置mod_alias: RedirectMatch 301 ^(.*)$ http://www.chedong.com
在域名和目录的规划方面: 豆瓣和FlickR都是非常干净的(完全隐藏了程序文件名的后缀,而统一规划了目录路径),而且在RSS方面豆瓣比FlickR做的更彻底。当然Wikipedia更彻底,目录结构非常扁平,根本没有目录。从而避免了很多潜在的连接混淆,而相互的引用,也因此非常集中而少歧义。
💬 历史评论
以下 4 条评论从旧版 Movable Type 博客迁移而来。 原始评论时间:2002–2016 年。
etng · 2007-11-09 13:08
我整理了一下,这样一个模板
example.virtualhost.template
ServerName example.com
this will redirect all the following format request to www.example.com
www.example.com/
example.com/
www.example.com
example.com
www.example.com/index.php
example.com/index.php
RewriteEngine on
RewriteRule ^(.*)$ http://www.example.com$1 [R=301,L]
# if you do not have mod_rewrite,uncomment the following line
#RedirectMatch 301 ^(.*)$ http://www.example.com
ServerName www.example.com
DocumentRoot "D:/projects/www.exmaple.comt/public"
…
21andy · 2007-11-17 21:36
这样的话还要加一个
ServerName www.xxx.com
21andy · 2007-11-17 21:39
这样做 www.就不能设置在同一个里了,不然www开头的自己转向自己
TanCee · 2008-10-25 23:25
我想问下,PHP如何设置301转向,但首页不进行301转向。