zoukankan      html  css  js  c++  java
  • ThinkPHP3 伪静态和URL重写 多重匹配的简单设置

    根据ThinkPHP3.0的手册URL重写的那一节配置Apache。

    然后再网站根目录下放置.htaccess文件,内容如手册所提示的一样

    win2003的空间iis6不支持.htaccess,尽可能选用linux系统的服务器

    Htaccess代码  收藏代码
    1. <IfModule mod_rewrite.c>  
    2.   
    3. RewriteEngine on  
    4.   
    5. RewriteCond %{REQUEST_FILENAME} !-d  
    6.   
    7. RewriteCond %{REQUEST_FILENAME} !-f  
    8.   
    9. RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]  
    10. 转载请注明出处:http://tyllxx.iteye.com  
    11. </IfModule>  

    虽然可以用URL_HTML_SUFFIX实现伪静态,但是这里的方法是使用.htaccess文件来实现。

    以上代码可以实现让:

    http://serverName/index.php/Blog/read/id/1

    变为:

    http://serverName/Blog/read/id/1

    那么还要让其变为:

    http://serverName/Blog/1.html

    若还有:

    http://serverName/buy/1.html

    http://serverName/topic/diy.html

    怎么实现呢?

    以下是实现方法:(.html后缀,自己在写连接时自己加上,用URL_HTML_SUFFIX方式,去掉方法中的.html)

    Htaccess代码  收藏代码
    1. <IfModule mod_rewrite.c>  
    2.   
    3.    RewriteEngine on  
    4.   
    5.    RewriteCond %{REQUEST_FILENAME} !-d  
    6.   
    7.    RewriteCond %{REQUEST_FILENAME} !-f  
    8.   
    9.    RewriteRule ^(.*)$ index.php/$1 [QSA,PT]  
    10.   
    11.    RewriteRule ^(.*)/topic/(.*).html$ $1/topic/Index/index/links/$2 [QSA,PT]  
    12.   
    13.    RewriteRule ^(.*)/buy/(.*).html$ $1/buy/Index/index/id/$2 [QSA,PT,L]  
    14.   
    15. 转载请注明出处:http://tyllxx.iteye.com  
    16. </IfModule>  

    此方法已经验证过,只需要修改匹配字段和替换字段即可使用。

    分享到:
  • 相关阅读:
    css3动画
    jquery和js进行添加样式
    网站基本了解
    新闻内容显示样式去除
    网页中常用的js特效
    手机和电脑同时兼容的网站
    使用repeter绑定数据的最高效率的方法
    常识(其他)
    OI暑假集训游记
    动态规划归纳(基础篇)
  • 原文地址:https://www.cnblogs.com/gzmg/p/3682928.html
Copyright © 2011-2022 走看看