腾讯云Ubuntu 14.04 & Apache 2.4.7 $ CI框架 之 如何去掉index.php后缀

来源:互联网 发布:mac终端编辑文件 编辑:程序博客网 时间:2024/06/14 20:30

摘要

CI框架默认有一个index.php作为入口,很讨厌,所以想要把它省略,而腾讯云服务器上我装的是Apache 2.4.7,所以需要配置一下


Apache Rewrite Module

这里需要说一句,想要去找httpd.conf的孩子可以省点心,不要去找了,Ubuntu下的Apache配置文件在/etc/apache2/apache2.conf里面。

  1. sudo a2enmod rewrite
    使用这个命令开启rewrite

  2. 更改/etc/apache2/apache2.conf文件
    照着写就对了,主要是* AllowOverride All *

这里写图片描述

  1. 去服务器所在目录touch一个.htaccess文件

这里需要注意,比如你的工程在/var/www/html/project里面,那么需要在project文件夹下新建这个文件。

touch .htaccess

注意权限

sudo chmod 777 .htaccess

然后添加如下代码到.htaccess

当服务器在根目录,即var/www/html下时

RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt)RewriteRule ^(.*)$ /index.php/$1 [L]

当服务器不在根目录,即var/www/html/project下时

RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt)RewriteRule ^(.*)$ /project/index.php/$1 [L]

最后记得重启服务器一下

service apache2 restart

然后就可以了。。。。

最后这一部分参考这里
http://blog.csdn.net/qq3559727/article/details/52370771

第一次配置,花了一个多小时,要死了

0 0
原创粉丝点击