温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎样去除index.php

发布时间:2020-11-05 09:40:16 来源:亿速云 阅读:122 作者:小新 栏目:编程语言

这篇文章将为大家详细讲解有关怎样去除index.php,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

去除index.php的方法:1、在apache中,编辑httpd.conf配置文件,并在框架根目录下新建htaccess;2、在nginx中,配置“$config['index_page'] = '';”,然后重启nginx即可。

apache去掉index.php

  1.编辑conf/httpd.conf配置文件

  #LoadModule rewrite_module modules/mod_rewrite.so 把该行前的#去掉

  同时对应Directory下要配置 AllowOverride All

  2.在 CI 根目录下(即在index.php,system的同级目录下)新建立一个配置文件,命名为: .htaccess 内容如下:

 RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond $1 !^(index\\.php|robots\\.txt)
  RewriteRule ^(.*)$ index.php/$1
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(application|modules|plugins|system|themes) index.php/$1 [L]

  3.把system/application/config/config.php 中$config['index_page'] = "index.php";改为$config['index_page'] = "";

  4.重启apache

nginx去掉index.php

  1.编辑nginx.conf文件

vi /usr/local/xxxxx/nginx/conf/nginx.conf
  #nginx去掉index.php
  location / {
  rewrite ^/$ /index.php last;
  #防止某些文件夹被直接访问
  rewrite ^/(?!index\\.php|robots\\.txt|uploadedImages|resource|images|js|css|styles|static)(.*)$ /index.php/$1 last;
  }

  2.config/config.php下配置$config['index_page'] = '';

  3..重启nginx

  去掉默认的index方法,如图的URL配置如:

  config/routes.php,配置$route['catalogues/(:any)'] = "catalogues/index/$1";

  其中(:any)表示匹配所有除CI保留关键字外的内容,后面的$1为index传入的参数内容。

  多个参数采用多个(:any),如两个参数的为:$route['catalogues/(:any)/(:any)'] = "catalogues/index/$1/$2";

  注:route规则如果同一目录下精确配置要在模糊配置上面,否则不起作用,如:

  $route['catalogues/more'] = "catalogues/more";
  $route['catalogues/(:any)'] = "catalogues/index/$1";

  注意事项

  route规则如果同一目录下精确配置要在模糊配置上面,否则不起作用

  nginx服务器不需要.htaccess文件

关于怎样去除index.php就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI