Heim  >  Artikel  >  Backend-Entwicklung  >  nginx配置对url解析有无/的问题

nginx配置对url解析有无/的问题

WBOY
WBOYOriginal
2016-06-06 20:39:211168Durchsuche

1.LNMP环境,访问:http://60.206.137.245/index.php ok
访问:http://60.206.137.245/index.php/ 404 not found (url多一个/)

2.WAMP环境,访问: http://boss.local/index.php/, url后面有无反斜杠/,都可以正常访问

1,2 都没有配置url重写, 怎么样可以让LNMP环境下 有无/,访问都是一样的了?

ps: 记得谁说标准的url都是以/结尾,像这样 http://www.test.com/index.php/?a=aa&b=bb,
但是实际中都是:http://www.test.com/index.php?a=aa&b=bb ,比前者index.php后面少个/

回复内容:

1.LNMP环境,访问:http://60.206.137.245/index.php ok
访问:http://60.206.137.245/index.php/ 404 not found (url多一个/)

2.WAMP环境,访问: http://boss.local/index.php/, url后面有无反斜杠/,都可以正常访问

1,2 都没有配置url重写, 怎么样可以让LNMP环境下 有无/,访问都是一样的了?

ps: 记得谁说标准的url都是以/结尾,像这样 http://www.test.com/index.php/?a=aa&b=bb,
但是实际中都是:http://www.test.com/index.php?a=aa&b=bb ,比前者index.php后面少个/

请将你的 匹配 php 文件的 location 写出来

如果大致是这样的:

<code>location ~* \.php$ {
    ....
}
</code>

可以修改为这样:

<code>location ~* \.php? {
    ...
}
</code>

并启用 pathinfo,php.ini 中的 pathinfo可以关闭,在 fastcgi.conf 文件中或者在 匹配 php 文件的location 中添加 nginx 的开启规则就可以了,其实 就是定义了一个变量而已:

<code>fastcgi_param PATH_INFO ^(.+?\.php)(/.+);
</code>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn