search

Home  >  Q&A  >  body text

thinkphp - When configuring rewrite in nginx, a 500 error occurs when words such as $1 appear.

#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. . .

PHPzPHPz2755 days ago575

reply all(3)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 17:22:17

    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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-16 17:22:17

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

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-16 17:22:17

    Try removing that regular expression

    reply
    0
  • Cancelreply