原来使用Apache2.2,只要开启使用rewrite模块,在Drupal中:管理(admin)-站点设置(settings)-简洁链接 (Clean URLS)里,Drupal会自动检测可以使用简介链接,选择启用(enable),就会使用默认的.htaccess文件来完成简洁链接的功能。
但是,当我把Apache2.2换为Lighttpd1.4.xx后,Drupal无法自动检测是否可以使用简洁链接功能。google一阵,发现解决的方法其实很简单。
首先,修改Lighttpd配置文件,比如我使用Lighttpd目录下的conf/lighttpd-inc.conf配置文件,那么就修改这个文件,开启rewrite模块:
server.modules
=
(
### 其他模块
### rewrite模块
" mod_rewrite "
)
### 其他模块
### rewrite模块
" mod_rewrite "
)
参考Drupal默认的.htaccess文件里rewrite模块部分:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q = $ 1 [ L,QSA ]
</IfModule>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q = $ 1 [ L,QSA ]
</IfModule>
看到没有,只有一条RewriteRule,就是它了。那么怎么样把它“移植”到Lighttpd的配置文件里呢?很简单,在Lighttpd配置文件里添加:
#### url handling modules (rewrite
,
redirect
,
access)
url.rewrite = ( " ^/cms/(.*)$ " = > " /cms/index.php?q=$1 " )
url.rewrite = ( " ^/cms/(.*)$ " = > " /cms/index.php?q=$1 " )
然后进入Drupal目录,修改sites/default/settings.php文件,在末尾处添加:
/**
* Clean URL
**/
$conf [ 'clean_url' ] = 1 ;
* Clean URL
**/
$conf [ 'clean_url' ] = 1 ;
现在访问http://wind/cms/,发现大部分功能都正常,比如用户登录。但是页面很粗糙,多媒体文件(图片什么的)和CSS排版都 没有加载,于是还需要增加一个RewriteRule,放在"^/cms/(.*)$" => "/cms/index.php?q=$1"的前面,现在的RewriteRule配置是这样子的:
#### url handling modules (rewrite
,
redirect
,
access)
url.rewrite = ( " ^/cms/(.*.gif|.*.png|.*.jpg|.*.pdf|.*.js|.*.css) " = > " /cms/$1 " , " ^/cms/(.*)$ " = > " /cms/index.php?q=$1 " )
url.rewrite = ( " ^/cms/(.*.gif|.*.png|.*.jpg|.*.pdf|.*.js|.*.css) " = > " /cms/$1 " , " ^/cms/(.*)$ " = > " /cms/index.php?q=$1 " )
现在访问http://wind/cms/,一切正常了哦!
WordPress的设置就更加简单了,依然查看WordPress 目录下的.htaccess文件,查看Apache下WordPress的RewriteRule,在Lighttpd的rewrite模块配置里添加一 条RewriteRule,最后Drupal/WordPress的rewrite模块配置是类似这样子的:
#### url handling modules (rewrite
,
redirect
,
access)
url.rewrite = ( " ^/blog/(archives|categories|comments|feed)/ " = > " /blog/index.php " , " ^/cms/(.*.gif|.*.png|.*.jpg|.*.pdf|.*.js|.*.css) " = > " /cms/$1 " , " ^/cms/(.*)$ " = > " /cms/index.php?q=$1 " )
url.rewrite = ( " ^/blog/(archives|categories|comments|feed)/ " = > " /blog/index.php " , " ^/cms/(.*.gif|.*.png|.*.jpg|.*.pdf|.*.js|.*.css) " = > " /cms/$1 " , " ^/cms/(.*)$ " = > " /cms/index.php?q=$1 " )
哈哈,是不是很简单呢?不过要注意,在rewrite模块配置之前请不要设置server.error-handler-404,不然只显示404错误哦~
(注:我是在公司局域网里架设的服务器,主机域名为http://wind/,www根目录为G:/pub。WinXP下Apache2 /Lighttpd+PHP5+MySQL5做服务器。Lighttpd使用FastCGI。Drupal目录为G:/pub /cms,WordPress目录为G:/pub/blog。)