Ubuntu-server 下Apache2 配置.htaccess 隐藏thinkPHP项目index.php无效解决办法

来源:互联网 发布:淘宝店招怎么加收藏 编辑:程序博客网 时间:2024/06/01 08:58

最近在做一个thinkphp的项目,想隐藏掉index.php.
首先按照网上的资料修改apache配置以及添加.htaccess
需要开启Apache2的rewrite模块
1、打开/etc/apache2/apache2.conf
将文件中的AllowOverride None改为AllowOverride All

2、修改mods-enable配置,添加一个软件链接

cd /etc/apache2/mods-enableln -s ../mods-avaiable/rewrite.load  rewrite.load

3、在项目根目录下添加.htaccess文件,修改rewrite规则

<IfModule mod_rewrite.c>    RewriteEngine on    #不显示index.php    RewriteCond %{REQUEST_FILENAME} !-d    RewriteCond %{REQUEST_FILENAME} !-f    RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfModule>

4、重启服务器

service apache2 restart

但是问题来了,添加好后,如果是windows就可以隐藏掉index.php了,但是在ubuntu下,还是不起作用。
原因如下:
1.在ubuntu下没有httpd.conf配置文件,只有apache2.conf,据说前者是用户自定义配置文件
2.apache2.conf中没有mod_rewrite.so(windows中把配置文件中包含这行的代码注释去掉即可完成配置)
解决办法:

a2enmod rewrite 

完成后重启服务器

参考文献:http://www.cnblogs.com/libertycode/p/5935761.html

阅读全文
0 0