tp3.1

一、url模式

    URL_MODEL
    1默认模式:pathinfo模式
    http://localhost/thinkphp3.1/index.php/Index/user/id/1.html
    0普通模式
    http://localhost/thinkphp3.1/index.php?m=Index&a=user&id=1
    2重写模式
    http://localhost/thinkphp3.1/Index/user/id/1.html
    3兼容模式
    http://localhost/thinkphp3.1/index.php?s=/Index/user/id/1.html

<?php
// 本类由系统自动生成,仅供测试用途
/*
1-输出配置文件的内容
2-url_model模式
*/
class IndexAction extends Action {
    public function index(){
    echo U('Index/user',array('id'=>1),'html',false,'localhost');
    }
    public function user() {
        echo 'id is'.$_GET['id'].'<br/>';
        echo '这里是index模块的user方法';
    }
}

二、隐藏index.php文件

  1默认模式:pathinfo模式
    http://localhost/thinkphp3.1/index.php/Index/user/id/1.html
    2重写模式
    http://localhost/thinkphp3.1/Index/user/id/1.html

如何实现index.php的隐藏?

1)LoadModule rewrite_module modules/mod_rewrite.so     开启

2).htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On    //重写机制
  RewriteCond %{REQUEST_FILENAME} !-d   //重写的条件
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]    //重写的规则
</IfModule>

即可以使用简写使用重写式

三、url的伪静态

http://blog.csdn.net/shuiaaa/article/details/6561793

伪静态,就是用户看到的地址以html.htm等静态页面的链接,实际还是动态页过,通过一些规则配置,显示在浏览器中的地址变为静态而以。

举个简单的例子:比如你的页面为/index.php通过伪静态显示在浏览器是index.html

class IndexAction extends Action {
    public function index(){
    echo U('Index/user',array('id'=>1),'html',false,'localhost');
    }
    public function user() {
        echo 'id is'.$_GET['id'].'<br/>';
        echo '这里是index模块的user方法';
    }
}

如果输入1.shtml   则显示id=‘1.shtml’;

如果将'URL_HTML_SUFFIX'       =>  'shtml',  // URL伪静态后缀设置

则id=1;此时输入1.html时,他又会认为id=1.html

如何设置多个: 'URL_HTML_SUFFIX'=>'shtml|html|xml',

原文地址:https://www.cnblogs.com/yanran/p/5118879.html