zoukankan      html  css  js  c++  java
  • PHP框架CodeIgniter--URL去除index.php

    今天学习CodeIgniter简称CI的第一天,记录下学习心得。

    CI中国https://codeigniter.org.cn/user_guide/general/urls.html?highlight=url 这里有介绍

    example.com/class/function/ID
    
    1. 第一段表示要调用的控制器 类 ;
    2. 第二段表示要调用的类中的 函数 或 方法 ;
    3. 第三段以及后面的段代表传给控制器的参数,如 ID 或其他任何变量;

    移除 URL 中的 index.php

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

    example.com/class/function/ID

    1、

    如果你的 Apache 服务器启用了 mod_rewrite ,你可以简单的通过一个 .htaccess 文件(放在index.php同级目录)

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

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

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

    或者不使用.htaccess 直接在apache配置文件中

    <Directory />
    Require all granted
    AllowOverride all
    Order allow,deny
    Allow from all
    </Directory>
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    </IfModule>

    2、

     httpd.conf 开启 LoadModule rewrite_module modules/mod_rewrite.so 
    如果已开启,可以忽略。
    3、重启apache
     
    4、application/config.php 中的$config['index_page'] = 'index.php';  --》index.php$config['index_page'] = '';
     
    http://192.168.1.89/welcome/index
  • 相关阅读:
    78. Subsets
    93. Restore IP Addresses
    71. Simplify Path
    82. Remove Duplicates from Sorted List II
    95. Unique Binary Search Trees II
    96. Unique Binary Search Trees
    312. Burst Balloons
    程序员社交平台
    APP Store开发指南
    iOS框架搭建(MVC,自定义TabBar)--微博搭建为例
  • 原文地址:https://www.cnblogs.com/cyun/p/6592347.html
Copyright © 2011-2022 走看看