thinkphp - When configuring rewrite in nginx, a 500 error occurs when words such as $1 appear.
PHPz
PHPz 2017-05-16 17:20:17
0
3
538
#rewrite .* /index.php last;
rewrite ^/(.*)$ /index.php/ last;

Of these two lines of code, the previous line can be used normally, but the following line will report an error as soon as it is used. Why? ? Is there any configuration that needs to be enabled? I looked at the documentation and couldn't find it. . .

PHPz
PHPz

学习是最好的投资!

reply all(3)
曾经蜡笔没有小新

rewrite ^/(.*)$ /index.php/ last; 代表的是 ^/(.*)$ 正则捕获的内容,也就是(.*) What was captured.

  • ^/(.*)$^/ 表示已 / 开头, . 表示匹配除换行符以外的任意字符,* 表示重复0次或更多次,$ 表示匹配字符串的结束,() means capturing (matching) content.

  • The content in parentheses ()之间匹配的内容,可以在后面通过来引用,表示的是前面第二个().

That is, when a request link is /test,就会被重写为/index.php/test并重定向到/index.php/test,所以请确保有这样的资源地址 /index.php/test

伊谢尔伦

Use nginx -t to test whether the configuration is correct.
500 error. Looking at the ErrorLog will usually tell you the reason

巴扎黑

Try removing that regular expression

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!