nginx重定向循环,从网址中删除index.php

jcampbell1

我想要任何类似的请求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/ 应该在以下位置提供index.php脚本 webroot/a/index.php

基本上,我永远不想在地址栏中显示“ index.php”。我有旧的反向链接,我需要将其重定向到规范URL。

cnst

很好的问题,我最近在ServerFault上回答了与另一个解决方案相似的解决方案,尽管这里的解决方案要简单得多,而且您确切地知道需要什么。

您想要的是仅在用户显式请求时执行重定向/index.php,而从不重定向最终由实际index.php脚本处理的内部请求(如通过index指令定义)

应该这样做,避免循环:

server {
    index index.php;

    if ($request_uri ~* "^(.*/)index\.php$") {
        return 301 $1;
    }

    location / {

        # ...
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

从网址中删除/重定向index.php以防止重复的网址

来自分类Dev

从网址中删除/重定向public / index.php以防止重复的网址

来自分类Dev

从网址中删除/重定向index.php以防止重复的网址

来自分类Dev

从重定向的PHP网站网址中删除“ index.html”

来自分类Dev

PHP网址重定向中的if else语句

来自分类Dev

在php中重定向时,使用jquery从网址中删除#location

来自分类Dev

CodeIgniter从网址中删除index.php

来自分类Dev

Nginx不会重定向到phpmyadmin的index.php页面

来自分类Dev

Nginx重定向为/stargate/index.php?seite=sga

来自分类Dev

Nginx不会重定向到phpmyadmin的index.php页面

来自分类Dev

将Nginx重定向到index.php

来自分类Dev

当用户提供重定向URL时,如何在yii中完全删除index.php

来自分类Dev

htaccess应该从当前URL中删除index.php,而是重定向到root

来自分类Dev

将/index.php重定向到/导致无限循环

来自分类Dev

从CodeIgniter删除并重定向index.php

来自分类Dev

.htaccess - 删除 index.php,使用多个参数重定向

来自分类Dev

PHP登录重定向循环

来自分类Dev

将旧域名网址重定向到新网址(index.php和其他网址除外)

来自分类Dev

在保留网址的同时重定向php

来自分类Dev

PHP / Htaccess网址重定向/映射

来自分类Dev

PHP获取最终重定向网址

来自分类Dev

从网址中删除.php

来自分类Dev

从网址中删除.php

来自分类Dev

php中的facebook SDK 4.0无限重定向循环

来自分类Dev

如何重定向网址是否具有index.php / somefileOrsomedirectory

来自分类Dev

HTML重定向中的PHP重定向

来自分类Dev

如何删除和重定向.htaccess中的子域的.php?

来自分类Dev

删除并重定向到PHP中的页面

来自分类Dev

从CodeIgniter 3中的网址中删除index.php

Related 相关文章

热门标签

归档