Home  >  Article  >  php教程  >  ThinkPHP3.2.3+Nginx的伪静态配置

ThinkPHP3.2.3+Nginx的伪静态配置

WBOY
WBOYOriginal
2016-06-07 11:34:291702browse

用TP框架开发的公司项目,URL模式是REWRITE模式('URL_MODEL' => 2,),上传至服务器,发现URL重写这块出现了问题,于是研究了一下,找到了答案,实践通过可用,分享给大家!
server<br>     {<br>         listen 80;    <br>         server_name www.vc.cn;<br>         <br>         index index.php;<br>         root  /data/wwwroot/vc;<br> <br>         #error_page   404   /404.html;<br>         location /<br>             {<br>                 index index.php;<br>                 #ThinkPHP REWRITE支持<br>                 if (!-e  $request_filename) {<br>                     rewrite ^/(.*)$ /index.php?s=$1 last;<br>                 }<br> <br>                 #301 跳转设置<br>                 if ($host = 'vc.cn') {<br>                         rewrite ^/(.*) http://www.vc.cn/$1 permanent;<br>                 }<br>             <br>             }        <br> <br>         location ~ [^/]\.php(/|$)<br>             {<br>                 # comment try_files $uri =404; to enable pathinfo<br>                 try_files $uri =404;<br>                 fastcgi_pass  unix:/tmp/php-cgi.sock;<br>                 fastcgi_index index.php;<br>                 include fastcgi.conf;<br>                 #include pathinfo.conf;<br>             }<br> <br>         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$<br>             {<br>                 expires      30d;<br>             }<br> <br>         location ~ .*\.(js|css)?$<br>             {<br>                 expires      12h;<br>             }<br> <br>         access_log  /home/wwwlogs/vc.log  access;<br>     }如以上代码注释【#ThinkPHP REWRITE支持】。
如果ThinkPHP项目安装在二级目录,Nginx的伪静态方法设置如下,其中subdir是所在的目录名称location /subdir/ {<br>         if (!-e $request_filename){<br>             rewrite  ^/subdir/(.*)$  /subdir/index.php?s=$1  last;<br>         }<br>     }

AD:真正免费,域名+虚机+企业邮箱=0元

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