2009年.cn域名最新价格WordPress专业空间WopusIDC推介有奖Cpanel教程汇总
充值大汇集cn25元,国际域名55WordPress CMS类免费主题Wopus中文平台
返回列表 回复 发帖

利用301让Wordpress的URL标准化

文章作者:Slyar 文章来源:Slyar Home (www.slyar.com) 转载请注明,谢谢合作。

首先我们要明白:什么是一个标准化URL?

这个概念是Google内部提出的,标准化是一个在若干选项中选取最佳URL的过程,这里通常是指主页。
例如,一般人会将以下URL看做是一样的:

* www.slyar.com
* slyar.com
* www.slyar.com/index.php
* slyar.com/index.php

但是从技术角度看,这些URL都是互不相同的。对于上述的URL,Web服务器会返回完全不同的内容。当Google“标准化”特定的URL时,它就会从同类URL中选出看起来最具代表性的一个。

现在我们就利用LINUX主机的.htaccess文件来使得我们的URL标准化。

首先是我的根目录,在根目录下上传以下内容的.htaccess文件,这个文件的地址是/.htaccess。这样当访问slyar.comwww.slyar.com/index.phpslyar.com/index.php时,由于301重定向的作用,所有的链接都会指向www.slyar.com,有兴趣的朋友可以点击链接测试我的网站首页。

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{http_host} ^slyar.com [NC]
RewriteRule ^(.*)$ http://www.slyar.com/$1 [L,R=301]
rewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
rewriteRule ^index\.php$ http://www.slyar.com/ [R=301,L]

如果你的Wordpress就在根目录下,那么将上面的内容加到Wordpress提供的.htaccess文件头部就行了。

其次就是我的Wordpress了,因为我的Wordpress安装在根目录下的/blog/里,所以我需要再次设置Wordpress提供的.htaccess文件,加入301转向代码的.htaccess文件如下,这个文件地址是/blog/.htaccess。这样当访问slyar.com/blogwww.slyar.com/blog/index.phpslyar.com/blog/index.php时,由于301重定向的作用,所有的链接都会指向www.slyar.com/blog/,有兴趣的朋友可以点击链接测试我的博客首页。

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{http_host} ^slyar.com [NC]
RewriteRule ^(.*)$ http://www.slyar.com/blog/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /blog/index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.slyar.com/blog [R=301,L]
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
Slyar Home  www.slyar.com
返回列表