douyaosi3164 2016-03-16 14:05
浏览 244
已采纳

简单的nginx重定向.php到主页

My old website had urls like:

domain.com/search.php?query=query
domain.com/product.php?id=id

I need to redirect requests to these files (and only these files) to:

domain.com

I'm using the Laravel framework that uses a single index.php file.

I've tried:

-Placing files named "search.php" and "product.php" in my root directory that redirects the user.

-Adding to Nginx conf:

location /search.php {
    return 301 http://domain.com;     
)
  • 写回答

1条回答 默认 最新

  • douzun4443 2016-03-16 14:25
    关注

    If your configuration file has a regex location for .php files, such as location ~ \.php$ { ... }. The regex location takes precedence over prefix locations, unless the ^~ modifier is used.

    You have three options: use an exact match location location =, use a regex location, or use the ^= modifier on a prefix location.

    To match two URIs, I might be inclined to use a regex:

    location ~* ^/(search|product)\.php {
        return 301 $scheme://$host/;
    }
    

    Make sure it is placed above the location ~ \.php$ block.

    See this document for details.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗