【问题标题】:Translate htaccess rewrite rule for nginx翻译 nginx 的 htaccess 重写规则
【发布时间】:2013-02-27 03:22:12
【问题描述】:
我想为 nginx 翻译以下 apache htaccess 重写规则。
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteRule ^(.+) /index.php
有什么办法吗?
【问题讨论】:
标签:
.htaccess
mod-rewrite
url-rewriting
nginx
rewrite
【解决方案1】:
apache重写规则解释清楚in the other question,特别是用于非替换的特殊破折号“-”规则。这可以在 nginx 中重写为 try_files 指令。
您的问题没有列出空字符串(主页)的规则(只有非空字符串 (.+))。所以我假设你在其他地方有一个主页规则。 nginx 中的规则可能是
location = / {
# your nginx rule matching the empty string (for your home page)
}
# all other locations try in the order: file => directory => index.php
location / {
try_files $uri $uri/ /index.php;
}