【发布时间】:2017-01-18 18:39:48
【问题描述】:
我在创建与我在 Nginx 上的 .htaccess 匹配的重写规则时遇到问题,我希望有人能指出我正确的方向。
我的 .htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt|app|assets|upload|api)
RewriteRule ^([^/]+)(?:/([^/]+)|)(?:/([^/]+)|)(?:/([^/]+)|) index.php?class=$1&action=$2¶m=$3 [L]
我的 nginx 配置
location / {
rewrite ^/([^/]+)(?:/([^/]+)|)(?:/([^/]+)|)(?:/([^/]+)|) /index.php?class=$1&action=$2¶m=$3 break;
}
查询参数是可选的,例如:
site.com/
site.com/customers
site.com/customers/add
site.com/customers/edit/1
我无法重写应用程序代码,因为 iam 只是从 apache 迁移到 nginx。
我们将不胜感激。
谢谢。
【问题讨论】:
标签: .htaccess mod-rewrite nginx url-rewriting query-parameters