.htaccess Nginx配置文件

.htaccess Nginx配置文件,.htaccess,nginx,.htaccess,Nginx,我对Nginx很陌生,我正在测试这是否是我未来的发展方向。在我的服务器上有几个网站。我成功地正确设置了Nginx。但是,在旧的设置中有一个.htaccess文件,确保所有URL都正常工作 这是.htaccess文件: RewriteEngine on RewriteBase / RewriteRule ^verzekeringen/([a-z]+)$ products/product/index.php?page=$1 [L] RewriteRule ^hypotheken/([a-z]+)$

我对Nginx很陌生,我正在测试这是否是我未来的发展方向。在我的服务器上有几个网站。我成功地正确设置了Nginx。但是,在旧的设置中有一个
.htaccess
文件,确保所有URL都正常工作

这是
.htaccess
文件:

RewriteEngine on
RewriteBase /

RewriteRule ^verzekeringen/([a-z]+)$ products/product/index.php?page=$1 [L]
RewriteRule ^hypotheken/([a-z]+)$ products/product/index.php?page=$1 [L]

RewriteRule ^verzekeringen$ products/index.php?type=1 [L]
RewriteRule ^hypotheken$ products/index.php?type=2 [L]
在线转换器,将其转换为:

# nginx configuration
location /verzekeringen {
    rewrite ^/verzekeringen/([a-z]+)$ /products/product/index.php?page=$1 break;
}
location /hypotheken {
    rewrite ^/hypotheken/([a-z]+)$ /products/product/index.php?page=$1 break;
}
location = /verzekeringen {
    rewrite ^(.*)$ /products/index.php?type=1 break;
}
location = /hypotheken {
    rewrite ^(.*)$ /products/index.php?type=2 break;
}
在标准配置文件中,有这个部分,我认为应该是。但问题是,我真的不知道如何将其合并到文件中

server {
    server_name testwebsite.nl www.testwebsite.nl;

    root /var/www/testwebsite.nl/htdocs;

    location ~ \.php$ {
        root           /var/www/testwebsite.nl/htdocs;
        fastcgi_pass   ***.*.*.*:****;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

}

实际上,您可以将生成的规则粘贴到
~\.php$
规则之前的任何位置

您还可以尝试以下方法:

server {
    server_name testwebsite.nl www.testwebsite.nl;

    root /var/www/testwebsite.nl/htdocs;

    location /verzekeringen {
       rewrite ^/verzekeringen/([a-z]+)$ /products/product/index.php?page=$1 break;
    }
    location /hypotheken {
       rewrite ^/hypotheken/([a-z]+)$ /products/product/index.php?page=$1 break;
    }
    location = /verzekeringen {
       rewrite ^(.*)$ /products/index.php?type=1 break;
    }
    location = /hypotheken {
       rewrite ^(.*)$ /products/index.php?type=2 break;
    }

    location ~ \.php$ {
        root           /var/www/testwebsite.nl/htdocs;
        fastcgi_pass   ***.*.*.*:****;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

} 
请参阅指令和


我尝试了你的代码,但它一直说
404找不到
对不起,我的朋友,我没有解释自动生成规则的行,假设生成器使用了良好的语法。试试我的编辑。没问题,但是,它仍然不断抛出一个
404
:SSorry再次,似乎我遗漏了一些东西,我已经按原样复制了生成的规则,正如我在评论中指出的那样。如果这样做行得通,那就是我的错,如果不行,那么生成的规则就缺少了对你方有利的东西。请让我知道。实际上这是生成代码的问题,而不是nginx。规则在逻辑上似乎很好,你们能不能用CMD中的cURL来表示你们得到的404地址,然后把它们粘贴到gist上?
location ~ ^/verzekeringen$ {
   rewrite ^(.*)$ /products/index.php?type=2 last;
 }

 location ~ ^/hypotheken$ {
   rewrite ^(.*)$ /products/index.php?type=1 last;
 }

 location ~ /verzekeringen/[a-z]+$ {
   rewrite ^/verzekeringen/(.*)$ /products/product/index.php?page=$1 last;
 }

 location ~ /hypotheken/[a-z]+$ {
   rewrite ^/hypotheken/([a-z]+)$ /products/product/index.php?page=$1 last;
 }