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

简单的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 微信小程序 用oss下载 aliyun-oss-sdk-6.18.0.min client报错
  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。
  • ¥15 抖音看过的视频,缓存在哪个文件