nginx redirect loop, remove index.php from url

前端 未结 5 1361
长情又很酷
长情又很酷 2020-11-29 03:25

I want any requests like http://example.com/whatever/index.php, to do a 301 redirect to http://example.com/whatever/.

I tried adding:

5条回答
  •  悲哀的现实
    2020-11-29 04:19

    If you already have first line mentioned below in your Nginx configuration file you don't have rewrite it again.

    index index.php index.html index.htm;

    rewrite ^(/.).html(?.)?$ $1$2 permanent;

    rewrite ^/(.*)/$ /$1 permanent;

    try_files $uri/index.html $uri.html $uri/ $uri =404;

    This will remove .html from the URL and additionally will also remove "index" from home page or index page. For example - https://www.example.com/index will be changed to https://www.example.com

提交回复
热议问题