【发布时间】:2014-03-08 09:06:17
【问题描述】:
我想要像 http://example.com/whatever/index.php 这样的任何请求,执行 301 重定向到 http://example.com/whatever/。
我尝试添加:
rewrite ^(.*/)index.php$ $1 permanent;
location / {
index index.php;
}
这里的问题是,这种重写在根 url 上运行,这会导致无限重定向循环。
编辑:
我需要一个通用的解决方案
http://example.com/ 应该提供文件webroot/index.php
http://example.com/index.php,应该 301 重定向到http://example.com/
http://example.com/a/index.php 应该 301 重定向到 http://example.com/a/
http://example.com/a/ 应该在webroot/a/index.php 处提供 index.php 脚本
基本上,我不想在地址栏中显示“index.php”。我有旧的反向链接,需要重定向到规范的 url。
【问题讨论】:
-
好吧,重定向循环是一个符合逻辑的事情,因为两个 URL 是相同的,
whatever/将调用index.php,因为您很可能在上面有一个index index.php行 -
我想 301 重定向外部 url,但在内部提供文件 index.php。我该怎么做?
标签: php nginx url redirect nginx-config