如何在nginx中使用重写规则 [英] How do I use rewrite rule in nginx

查看:95
本文介绍了如何在nginx中使用重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将我的htaccess代码转换为nginx conf。我想将文件重定向到download.php?file = ....但无论我做什么,它都不起作用。



这是我的htaccess代码:

Hi, i tried to convert my htaccess code to nginx conf. I want to redirect files to download.php?file=.... but whatever I do, it doesn't work.

Here is my htaccess code:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^/(.*)$ /download.php?file=$1 [R=301]





我用http://winginx.com/en/htaccess



,结果如下:



I've converted it using http://winginx.com/en/htaccess

and here is the result:

# nginx configuration
server{
location / {
if (-e $request_filename){
rewrite ^/(.*)$ /download.php?file=$1 redirect;
}
}
}





Nginx忽略它,文件位于/ home / admin /domains/mydomain.com/public_html/甚至我在旁边/

使用它但我得到了相同的结果。

有什么解决方案吗?



Nginx ignores it, files are located in /home/admin/domains/mydomain.com/public_html/ and even I used it beside /
but i get the same result.
Is there any solution?

推荐答案

/download.php?file =
/download.php?file=


1 [R = 301]
1 [R=301]





我使用 http://winginx.com/en/htaccess 转换了它



这里是结果:



I've converted it using http://winginx.com/en/htaccess

and here is the result:

# nginx configuration
server{
location / {
if (-e


request_filename){
rewrite ^ /(。*)
request_filename){ rewrite ^/(.*)


这篇关于如何在nginx中使用重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆