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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kunpeng1987/article/details/72875459

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

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

cd /etc/apache2/mods-enable
ln -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

猜你喜欢

转载自blog.csdn.net/kunpeng1987/article/details/72875459
今日推荐