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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值