我使用在线转换器将以下Apache mod_rewrite转换为NginX重写:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1 [R=301,L]
输出看起来像这样:
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite /. /index.php last;
}
if ($http_host ~* "^www.(.*)$"){
set $rule_1 1$rule_1;
set $bref_1 $1;
}
if ($rule_1 = "1"){
rewrite ^/(.*)$ http://$bref_1 permanent;
}
尽管在添加到vhosts文件时转换工作正常,但我已经向我指出转换效果不佳以及http://docs.ngx.cc/en/latest/topics/depth/ifisevil.html
有人可以帮助我进行“正确”转换吗?
谢谢。
答案 0 :(得分:0)
这主要是应该做的,问题在于你想要传递给index.php
server {
server_name example.com;
root /path/to/www;
location / {
try_files $uri $uri/ /index.php$request_uri
}
}
server {
server_name www.example.com;
return 301 example.com;
}