zoukankan      html  css  js  c++  java
  • IIS 环境 CodeIgniter 隐藏 URL 中的 index.php

    在 IIS 环境搭建好 CI 框架后,默认的URL如下,其中的“index.php”甚是影响美观。

     去掉的方法也较为简单。首先参照 CI 说明( https://codeigniter.org.cn/user_guide/general/urls.html#url-index-php ),移除链接中的URL地址。

    默认情况,你的 URL 中会包含 index.php 文件:

    example.com/index.php/news/article/my_article
    

    如果你的 Apache 服务器启用了 mod_rewrite ,你可以简单的通过一个 .htaccess 文件再加上一些简单的规则就可以移除 index.php 了。下面是这个文件的一个例子, 其中使用了 "否定条件" 来排除某些不需要重定向的项目:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    在上面的例子中,除已存在的目录和文件,其他的 HTTP 请求都会经过你的 index.php 文件。

    而博主并未验证上述内容,在 CI 框架根目录下添加 .htaccess 文件(在 VS Code IDE中)后实际填写的内容为:

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

    IIS 还需要在网上下载一个 ISAPI_Rewrite,运行程序后,点开相应网站,并应用 .htaccess 即可(之后关闭该窗口也不影响)。

     以下是配置成功后的效果。

  • 相关阅读:
    thinkphp模块设计
    thinkphp自动创建目录
    thinkphp入口文件
    thinkphp目录结构
    thinkphp环境要求
    获取ThinkPHP
    QueryList getData()方法中多次调用来实现递归多级采集。
    PHP count() 函数
    PHP mysqli_affected_rows() 函数
    QueryList 内容过滤
  • 原文地址:https://www.cnblogs.com/xunzhiyou/p/12094326.html
Copyright © 2011-2022 走看看