• 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

     
  • 相关阅读:
    2013dgtcs 成绩排序
    JZOJ 1286. 太空电梯
    java单例模式Singleton
    设计模式的类型
    java工厂模式Factory
    Mysql SQL优化
    maven deploy命令打包到私服
    debian/linux 配置maven
    Java RC4加密解密工具
    JedisUtils
  • 原文地址:https://www.cnblogs.com/lmei/p/3370006.html
Copyright © 2020-2023  润新知