zoukankan      html  css  js  c++  java
  • CI去掉 URL 中的 index.php

    首先,你要清楚自己的 Web 服务器是 Apache,支持 mod_rewrite

    查找httpd.conf中是否开启了mod_rewrite.so

    然后,在 CI 根目录下新建立一个配置文件,命名为: .htaccess
    在里面这样写:

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

    就可以去掉 index.php 了。要注意 ./index.php/$1 要根据你目录(Web 目录,比如 http://www.domain.com/index.php)的实际情况来定,比如网站根目录是 /ci/index.php 则要写成 /ci/index.php/$1

    RewriteCond $1 !^(index.php|images|robots.txt)

    上面的代码意思是排除某些目录或文件,使得这些目录不会 rewrite 到 index.php 上,这一般用在图片、js、css 等外部资源上。也就是说非 PHP 代码都要排除出去。(这里我排除了 images 目录和 robots.txt 文件,当然 index.php 也应该被排除)
    哦,对了,还要修改 config.php 这个文件中的下列内容:

    /*
    |--------------------------------------------------------------------------
    | Index File
    |--------------------------------------------------------------------------
    |
    | Typically this will be your index.php file, unless you've renamed it to
    | something else. If you are using mod_rewrite to remove the page set this
    | variable so that it is blank.
    |
    */
    $config['index_page'] = "index.php";

    把其中的 "index.php" 改成 "" 就可以了。

    时不我待,不负韶华!立刻行动!不吃学习的苦就会吃生活的苦!
  • 相关阅读:
    [Abp vNext 源码分析]
    C# 结合 PInvoke 对接 IP 摄像头的笔记
    Abp vNext 自定义 Ef Core 仓储引发异常
    [Abp vNext 源码分析]
    [Abp vNext 源码分析]
    [Abp vNext 源码分析]
    网站SEO中服务器优化的三个问题
    用香港服务器还是国内服务器好
    租用香港服务器最重要的三个问题
    如何选择服务器操作系统
  • 原文地址:https://www.cnblogs.com/zrp2013/p/3556772.html
Copyright © 2011-2022 走看看