鉴行志

A blogging framework for hackers.

wordpress配置及网站SEO

| Comments

前一段时间使用wordpress 的一个缓存插件,几天使用下来发现好像没有起到缓存作用。晚上查了下nginx配置,终于找到了为什么。原来是我的nginx配置不对,缓存的路径没有设置对。
找到了问题改正就很容易了。同时也把使用插件生成sitemap.xml也进行了重写,搜索引擎也可以很好的索引相关网页。

 
#如果文件存在直接返回,并设定7天的缓存期
    if (-f $request_filename) {
        expires 7d;
        break;
    }
#初始supercache缓存变量
    set $supercache_file ”;
    set $supercache_uri $request_uri;
#post不访问缓存
    if ($request_method = POST) {
        set $supercache_uri ”;
    }
 
# 因为使用了url重写,因此有查询条件就不访问缓存
    if ($query_string) {
        set $supercache_uri ”;
    }
# 如果有缓存,也不访问缓存
    if ($http_cookie ~* “comment_author_|wordpress|wp-postpass_” ) {
        set $supercache_uri ”;
    }
 
# 如果变量不为空,则访问缓存地址
 
    if ($supercache_uri ~ ^(.+)$) {
        set $supercache_file /wp-content/cache/supercache/$http_host/$1index.html;
    }
 
# 如果缓存存在,则返回缓存文件
    if (-f $document_root$supercache_file) {
        rewrite ^(.*)$ $supercache_file break;
    }
#sitemap 重写,动态生成sitemap.xml
rewrite ^/(sitemap.*)\.xml$ /index.php?feed=$1;
# 其它访问都内 index.php处理
    if (!-e $request_filename) {
        rewrite . /index.php last;
    }
  }

原来网站使用两个域名,两个域名下都是同样的内容。据说这个不利于SEO,搜索引擎也会有惩罚策略。所以就在其中一个域名上设置了301转移重写。

 
server_name  www.xiangjian.info xiangjian.info;
rewrite ^ http://blog.xiangjian.info$uri permanent;

EOF

Comments