Home >Backend Development >PHP Tutorial >How to rewrite the url in laravel under nginx in the secondary directory of the website directory

How to rewrite the url in laravel under nginx in the secondary directory of the website directory

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 09:05:342804browse

我用的是nginx1.9.9,laravel 5.1.11版本。
项目多的人都会感受到,localhost下面一堆的文件夹一堆的项目,每次有新项目就习惯直接在网站根目录下面放了,毕竟在本地开发调试,怎么方便怎么来。
因此我localhost里面就好多东西了,http://localhost/asd/,或者 http://localhost/caugoo/类似这样的很多,但是现在很多的php框架都要来个路由,配置个url重写,在apache下面搞很方便,但是在nginx下就要搞多几下了。
以我新项目为例子,该项目要求用laravel来做,因此我把整个项目丢到一个叫laravel的文件夹里面了,目录就变成c:/nginx/html/laravel了,然后发现只能通过localhost/laravel/public来访问,毕竟laravel的入口文件index.php在public里面。
查找了一番发现laravel根目录下的server.php也可以达到这样的效果,把server.php重命名成index.php,然后再在nginx那个配置文件加上下面的代码,成功url重写到这个index.php上了。。。

同理,在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;
            }
        }

以上就介绍了nginx下的laravel在网站目录的二级目录下url重写的方法,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

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
Previous article:91 php namespace 1Next article:91 php namespace 1