drupal学习经验(url rewrite)

张映 发表于 2011-01-02

分类目录: drupal

标签:, ,

drupal的url重写,后台有地方进行控制的,administer=>Site configuration=>Clean urls在这里我们可以选择,开启url重写,或者是不开启,里面有一个单选框,如果是不可选的,说明你服务器中的url重写并没有配置好,会提示以下错误

Your system configuration does not currently support this feature. The handbook page on Clean URLs has additional troubleshooting information.

要想使用http://localhost/drupal/?q=admin/settings/clean-urls这里面的单选可以点,要做到一下三步

一,查机apache的服务器是不是加载了mod_rewrite.so

有很多种方法可以查看

1,apache2ctl -M

2,我们可以打开一下,apache的配置文件httpd.conf,看里面有没有LoadModule rewrite_module modules/mod_rewrite.so,如果没有的话就加上,如果存在把前面的注释#去掉

3,对于做php的人来说,我们可以通过phpinfo();来查看一下rewrite模块是否可用

二,重新规则

安装完drupal后,在drupal的安装根目录下吗,会自动产生一个.htaccess的文件,里面带了一些重写规则,你可以用这些规则。

  1. <IfModule mod_rewrite.c>  
  2.  RewriteEngine on  
  3.  RewriteBase /                                                           //在这里/代表的根目录,RewriteBase /drupal/ ,表示重写到/drupal/目录下面  
  4.  RewriteCond %{REQUEST_FILENAME} !-f  
  5.  RewriteCond %{REQUEST_FILENAME} !-d  
  6.  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]  
  7. </IfModule>  

我们也可以利用apache的配置文件来完成,你可以放在httpd.conf里面,或者放在httpd_vhost.conf里面

  1. <Directory /home/zhangy/www/drupal>  
  2.  RewriteEngine on  
  3.  RewriteBase /  
  4.  RewriteCond %{REQUEST_FILENAME} !-f  
  5.  RewriteCond %{REQUEST_FILENAME} !-d  
  6.  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]  
  7. </Directory>  

还有一点,也是是容易让人疏忽的一点就是,

  1. <Directory "/home/zhangy/www/drupal">  
  2. 。。。。。。。。。。  
  3.  AllowOverride All                             //默认情况下,是none的,把none改成all  
  4. 。。。。。。。  
  5. </Directory>  

三,进入drupal后台,启用url rewrite功能

administer=>Site configuration=>Clean urls现在我们要以发现Your server has been successfully tested to support this feature

说明rewrite没什么问题,选中enabled,保存一下就搞好了。



转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/drupal/1195.html