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

简单的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;     
)

图片转代码服务由CSDN问答提供 功能建议

我的旧网站的网址如下:

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

我需要将请求重定向到这些文件(并且只有这些文件):

domain.com

我正在使用使用单个index.php文件的Laravel框架。

I 尝试过:

- 在我的根目录中放置名为“search.php”和“product.php”的文件,重定向用户。

- 添加到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.

    点赞 评论

相关推荐 更多相似问题