zoukankan      html  css  js  c++  java
  • ThinkPHP -- 去除URL中的index.php

    • 原路径是 http://localhost/test/index.php/index/add
    • 想获得的地址是 http://localhost/test/index/add
    • 那么如何去掉index.php呢? @_@!!
     
    (1)apache 设置
    •   httpd.conf配置文件中加载了mod_rewrite.so模块 
    LoadModule rewrite_module modules/mod_rewrite.so
    • AllowOverride None 讲None改为 All
    <Directory />
        Options FollowSymLinks
        AllowOverride All
        Order deny,allow
        Deny from all
    </Directory>

    (2)确保URL_MODEL设置为2,在项目的配置文件config.php里

    return Array(
          ……
        'URL_MODEL' => '2',
          ……
    );

    (3)添加.htaccess文件,并添加如下代码,必须放到项目根目录下

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
    </IfModule>
     
    补充:在windows下不能建立以点开头的文件,你可以先随便建立一个文件

    然后在DOS在操作 rename xxxx.xxxx .htaccess

    或者打开记事本写入htaccess然后另存为.htaccess即可

    如果出现403错误则将.htaccess打开在开头添加Options +FollowSymLinks
     
    即如下所示:
    Options +FollowSymLinks
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
    </IfModule>

    即可解决。
    无权限也是加上Options +FollowSymLinks

     
  • 相关阅读:
    java反射
    sql语句
    menu
    亮度
    自定义View
    将多层级xml解析为Map
    Theme.AppCompat无全屏主题解决办法
    Android EditText 限制输入为ip类型
    请不要乱用Kotlin ? 空检查
    配置 jvisualvm 监控Java虚拟机
  • 原文地址:https://www.cnblogs.com/lmei/p/3370006.html
Copyright © 2011-2022 走看看