简体   繁体   English

HTACCESS规则到NGINX配置文件(一个规则)

[英]HTACCESS Rule to NGINX Configuration File (One Rule)

I'm struggling with getting one rule that I had in my HTACCESS file, to work within my NGINX configuration files. 我正在努力获取HTACCESS文件中包含的一条规则,以便在NGINX配置文件中工作。 I've used the converters online, and searched on Google but can't seem to find a solution that'll work. 我已经在线使用了转换器,并在Google上进行了搜索,但似乎找不到可行的解决方案。 I feel this would be a quick solution for someone a bit more familiar with NGINX redirects. 我觉得对于熟悉NGINX重定向的人来说,这将是一个快速的解决方案。 I sure hope so! 我当然希望如此! :-) :-)

HTACESS Rule: HTACESS规则:

RedirectMatch 301 ^/services/automotive-services/(.*)$ http://www.domain.com/automotive-services/$1

I'm trying to get my NGINX rule to do the following... 我正在尝试让我的NGINX规则执行以下操作...

Any assistance with this would be great! 任何帮助都会很棒! :-) :-)

You have to remember that Nginx does not do anything with htaccess files. 您必须记住,Nginx对htaccess文件不做任何事情。 Htaccess files are purely an Apache construct. Htaccess文件纯粹是Apache构造。

As for how you would do the RedirectMatch in Nginx, put this in your server configuration: 至于在Nginx中如何进行RedirectMatch,请将其放入服务器配置中:

if ( $request_filename ~ services/.+ ) {
   rewrite ^(.*) http://www.domain.com/$1 permanent;
}

This will check if $request_filename contains "services", and if it does, it will rewrite it via 301 to http://www.domain.com/ . 这将检查$request_filename包含“服务”,如果包含,则将通过301将其重写为http://www.domain.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM