Category: Architecture

一般我们常用www.eood.cn这样的域名作为主站域名, 但是无www前缀的域名也很常见。假如只设置www域名,有些人直接输入无www的域名将找不到你的网站,这样会损失很大一部分流量。但是如果将有无www前缀的域名都指向自己的网站,又会造成SEO中重复文章的问题, 你将会发现搜索引擎中一部分是带www前缀的url,另一部分则没带。还会出现文章索引减少等很多问题。所以我们必须了解如何正确使用这两个域名。

正确的做法是将一个域名301重定向的另一个域名

比如你使用带www前缀的域名作为主域名,可以将无www前缀的域名下的所有请求301重定向到主域名下对应的URL上。

将无www域名指向空白的目录,目录下只保留一个.htaccess文件, 文件内容为(以eood.cn为例)

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

这样所有流量会引向正确的URL,还不会造成重复内容的问题。

这种设置方法还可以用在更换域名的情况下,比如你要更换老域名www.a.com为www.b.com, 将主站域名换成www.b.com后,将www.a.com指向空白目录,目录下只保留一个.htaccess文件,文件内容为

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.a.com
RewriteRule (.*) http://www.b.com/$1 [R=301,L]

这样设置后无论搜索引擎爬虫还是用户都会自动跳转到正确的URL上。老网站的PR会逐步向新网站迁移。

对于Linux服务器管理员来说, .htaccess文件几乎没人不知道。现在大部分网站都用它还做URL rewrite。URL 路径改写几乎是流行的CMS的必备功能。
但是Htaccess还有其他很多强悍的功能:

1. 设置时区

这个设置会影响PHP中的date函数
SetEnv TZ [Time zone]

2. 301网址重定向

现在主要的搜索引擎都已支持301重定向,这个功能对于网站改域名非常重要
Redirect 301 http://eood.cn http://blog.eood.cn

3.跳过下载确认对话框

现在很多网址下载文件都会弹出打开或者保存文件的对话框,如何跳过这个对话框直接打开文件?
AddType application/octet-stream .pdf
AddType application/octet-stream .zip
AddType application/octet-stream .mov

4.省略域名中的www

SEO中很重要的一条就是每个网页只有一个链接指向,否则会被判定为重复文章,如何让www的URL全部指向省略www的URL?
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.eood.cn [NC]
RewriteRule ^(.*)$ http://eood.cn/$1 [L,R=301]

5.自定义错误页面

ErrorDocument 401 /error/401.php
ErrorDocument 403 /error/403.php
ErrorDocument 404 /error/404.php
ErrorDocument 500 /error/500.php

6.压缩文件

在客户端请求过程中对文件压缩,可以提高下载速度

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

7.缓存大文件

WEB游戏如今非常盛行,Flash客户端动辄几M,每次都让玩家加载肯定是不行的,如何让不常更新的大文件缓存在客户端?

Header set Cache-Control “max-age=2592000″

8.禁止在此目录执行脚本

AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -ExecCGI

Sell your blog links

Activate Linode VPS
Best VPS Service

Workflow in Drupal

Workflow is the essential feature of complex modern system. Lots of automate process can be implemented if the workflow states defines.And it contributed to the ACL system.
Think of the following situations:
1. The Draft news should only be shown to moderator. After moderation, the state changed to open. And open news should be shown to All automatically.
2. In the open state, some field shows to all, and some hidden, only can be seen by some roles.
3. In the Draft state, some fields such as title can not be edited, but other fields can be edited.
4. The job can be processed just after money access. Automatically change the state of the job. (By Trigger)
5. The payment process
6. Automatically hide the article after open 1 weeks.
In Drupal, workflow module always work together with Actions*, Triggers*, VBO*. Triggers can be assigned to the workflow changes. Do something automatically when the workflow changes. Triggers fire the Actions* we defined.

How to define Actions, please see our other articles.

Important feature or bug of workflow module of Drupal:
When a new CCK field added to a content type. The workflow of this state should be saved again, or the field will not be constrained by Workflow.

Change the workflow programmingly in one line:

<?php
    workflow_execute_transition(node_load($nid), 21, 'Test comment ',TRUE);
?>

You can change the workflow state by Trigger*, by cron and conditions, by xmlrpc, etc.