我想要任何像 example/whatever/index.php 的请求,做一个 301 重定向到 example/whatever/.
I want any requests like example/whatever/index.php, to do a 301 redirect to example/whatever/.
我尝试添加:
rewrite ^(.*/)index.php$ $1 permanent; location / { index index.php; }这里的问题是,这个重写在根 url 上运行,这会导致无限重定向循环.
The problem here, this rewrite gets run on the root url, which causes a infinite redirect loop.
我需要一个通用的解决方案
I need a general solution
example/ 应该提供文件 webroot/index.php
example/index.php,应该 301 重定向到 example/
example/index.php, should 301 redirect to example/
example/a/index.php 应该 301 重定向到 example/a/
example/a/index.php should 301 redirect to example/a/
example/a/ 应该在 webroot/a/index.php
基本上,我不想在地址栏中显示index.php".我有旧的反向链接,需要重定向到规范网址.
Basically, I never want to show "index.php" in the address bar. I have old backlinks that I need to redirect to the canonical url.
推荐答案很好的问题,有解决方案 类似于我最近在 ServerFault 上回答的另一个问题,尽管这里简单得多,而且您确切地知道自己需要什么.
Great question, with the solution similar to another one I've answered on ServerFault recently, although it's much simpler here, and you know exactly what you need.
您在这里想要的是仅在用户明确请求 /index.php 时才执行重定向,而不要重定向最终由实际 index 提供服务的任何内部请求.php 脚本,通过 index 指令定义.
What you want here is to only perform the redirect when the user explicitly requests /index.php, but never redirect any of the internal requests that end up being served by the actual index.php script, as defined through the index directive.
这应该做到这一点,避免循环:
This should do just that, avoiding the loops:
server { index index.php; if ($request_uri ~* "^(.*/)index.php$") { return 301 $1; } location / { # ... } }更多推荐
nginx 重定向循环,从 url 中删除 index.php
发布评论