.htaccess转web.config适用于ThinkPHP设置伪静态

其实我们做PHP开发的,最常用的PHP环境无非是wamp,但目前为止,许多windows的服务器环境还都是IIS搭配的,所以从apache的htaccess做的伪静态就不得不重写了,因为IIS不支持htaccess,下面我们就来讲解一下如何将.htaccess文件转换成对应的web.config文件。

.htaccess


RewriteEngine on
RewriteCond %{REQuEST_METHOD} ^TRACE
RewriteRule .* - [F]

#RewriteCond %{http_host} ^www.liqingbo.cn [NC]
#RewriteRule ^(.*)$ http://liqingbo.cn/$1 [L,R=301]


#RewriteLog "rewrite.log"
#public目录,sys目录...,不进行重写
RewriteCond %{REQuEST_uRI} !^(/public(.*)|/Public(.*)|/sys(.*)|/Themes(.*))$
#这些后缀的文件,不进行RewriteRule
RewriteCond %{REQuEST_uRI} !^.*(.css|.js|.gif|.png|.jpg|.jpeg|.bmp)$ 
RewriteCond %{REQuEST_FILENAME} !-d
RewriteCond %{REQuEST_FILENAME} !-f 
#RewriteBase /index.php
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]


RewriteRule /news/show-([0-9]+) /News/show/id/$1
RewriteRule /news/list-([0-9]+) /News/index/cid/$1

RewriteRule /product/show-([0-9]+) /product/show/id/$1
RewriteRule /product/list-([0-9]+) /product/index/cid/$1

RewriteRule /singlepage/show-([0-9]+) /Singlepage/show/id/$1

ErrorDocument 404 /404.html
order deny,allow

转换后:

web.config



    

  
    
    
      
      
    

    
      
      
        
        
        
        
      
      
    
    
    
      
      
    
    
      
      
    
    
    
      
      
    
    
      
      
    
  

    

其实一开始伪静态是不起作用的,后来实在没办法了,只能死马当活马医了,随便捣腾了一下,还真可以实现了,不过到目前为止,我还是不太明白其中原因。

如图:

QQ截图20170318021525.png

只要这两个为止互换一下,就不伪静态就不起作用了,真不知道为什么,还希望看明白的人能给我个提示,在下感激不尽。

温馨提示: 本文最后更新于2024-12-31 21:11:09,某些文章具有时效性,若有错误或已失效,请在下方 留言或联系 蚂蚁官方
© 版权声明
THE END
喜欢就支持一下吧
点赞14赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容