溫馨提示×

nginx.conf中的rewrite指令如何使用

小樊
94
2024-08-14 01:26:36
欄目: 編程語言

在nginx.conf文件中,可以使用rewrite指令來重定向URL。語法如下:

rewrite regex replacement [flag];

其中,regex是一個(gè)正則表達(dá)式,匹配需要重定向的URL。replacement是重定向后的URL或者重定向規(guī)則。flag是一個(gè)可選的標(biāo)志,用于指定重定向的行為。

例如,如果想要將所有以/example開頭的URL重定向到/example.html,可以使用以下配置:

rewrite ^/example(.*)$ /example.html$1 last;

這樣,當(dāng)訪問http://example.com/example時(shí),將會(huì)被重定向到http://example.com/example.html

0