Home  >  Article  >  Backend Development  >  ThinkPHP中pathinfo的访问模式、路径访问模式及URL重写总结_PHP

ThinkPHP中pathinfo的访问模式、路径访问模式及URL重写总结_PHP

WBOY
WBOYOriginal
2016-05-31 19:30:16818browse

ThinkPHP

本文针对ThinkPHP中pathinfo的两种模式、四种路径访问模式和URL重写相关知识进行了总结归纳,分享给大家便于查询和借鉴。具体归纳如下:

1、pathinfo

访问模块IndexAction.class.php下边的test方法

   http://localhost/index.php?m=Index&a=test 等同于 http://localhost/index.php/Index/test

2、四种路径访问模式
   
在config目录下边来做修改 URL_MODEL的值,分别表述如下:

值为0   叫做普通模式。如:http://localhost/index.php?m=模块&a=方法
值为1   叫做pathinfo模式。如:http://localhost/index.php/模块/方法
值为2   叫做rewrite重写(伪静态) 可以自己写相关的rewrite规则,也可以使用系统为我们提供的rewrite规则隐藏掉index.php,生成:http://localhost/模块/方法
值为3   叫做兼容模式。当服务器上面不支持pathinfo模式的时候,但是你又在之前的路径访问格式上面,全部用的是pathinfo格式。那么它会提示你路径格式不正确。那么,你就可以用标号为3的兼容模式来处理。他的路径访问类似于http://localhost/index.php?s=模块/方法 

3、URL重写步骤:
 
(1)、D:\wamp\wamp\Apache2\conf\httpd.conf开启apache服务器中的URL_REWRITE模块 

(2)、AllowOverride None 将 None 改为 All

(3)、确保config.php配置文件中 URL_MODEL 设置为 2

(4)、把 .htaccess 文件放到入口文件的同级目录下
   
采用URL重写利于seo,不过会加大服务器的性能消耗。

希望本文所述对大家ThinkPHP程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn