nginx下如何l在网站目录的二级目录下url重写的方法

以我新项目为例子,该项目要求用laravel来做,因此我把整个项目丢到一个叫laravel的文件夹里面了,目录就变成c:/nginx/html/laravel了,然后发现只能通过localhost/laravel/public来访问,毕竟laravel的入口文件index.php在public里面。

在nginx下配置其他框架也差不多如此,比如thinkphp,而且还不需要改什么server.php文件,因为thinkphp这些框架根目录就是index.php了。

location /laravel/ {  

       index  index.html index.htm index.php;  

  if (!-e $request_filename){  

                rewrite  ^/laravel/(.*)$  /laravel/index.php?s=$1  last;  

        }  

}  

1、项目在根目录:

        location / {
            index  index.html index.htm index.php l.php;
            autoindex  on;

            if (!-e $request_filename) {
                  rewrite ^/index.php(.*)$ /index.php?s=$1 last;
                  rewrite ^(.*)$ /index.php?s=$1 last;
                  break;
            }
        }

2、项目在二级目录: localhost/YII/basic/web

    location /YII/basic/web/ {  
               index  index.html index.htm index.php l.php;
               autoindex  on;
            if (!-e $request_filename){    
                rewrite  ^/YII/basic/web/(.*)$  /YII/basic/web/index.php?s=$1  last;    
            }
        }

原文地址:https://www.cnblogs.com/feixiablog/p/8885960.html