【发布时间】:2014-07-27 03:25:51
【问题描述】:
刚接触 nginx,完全一头雾水。
如何将此 URL 重写转换为 nginx?
<rewrite>
<rules>
<rule name="IndexFolders" stopProcessing="true">
<match url="(.*[^/]+)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" />
</conditions>
<action type="Rewrite" url="/_index/{R:1}.html" />
</rule>
<rule name="OtherFile" stopProcessing="true">
<match url="\.\w+$" />
</rule>
<rule name="HtmlFile" stopProcessing="true">
<match url="^([^.]*[^/]+)$" />
<action type="Rewrite" url="{R:1}.html" />
</rule>
</rules>
</rewrite>
尝试了转换器,但无法正常工作。
location / {
if (-d $request_filename){
set $rule_0 1;
}
if ($rule_0 = "1"){
rewrite /(.*[^/]+)$ /_index/$1.html last;
}
location ~* /\.\w+$ {
break;
}
rewrite ^/([^.]*[^/]+)$ /$1.html last;
}
【问题讨论】:
-
改用
rewrite /?([^/]+)$。 -
@hjpotter92 你是什么意思?尝试不工作,现在出现 500 个错误
-
location ~* /\.\w+$ { break; }应该是if ($uri ~* \.\w+$) { break; },break表示它将停止在location / {}中运行其他重写规则
标签: .htaccess iis nginx url-rewriting