HTACCESS 2 NGINX规则,任何可以帮助我?

时间:2014-09-14 12:46:37

标签: apache .htaccess mod-rewrite nginx

我有一个站点需要从apache2移动到nginx,一切正常,除了htaccess。我有谷歌一些在线工具(http://www.anilcetin.com/convert-apache-htaccess-to-nginx/& http://winginx.com/en/htaccess ...),但他们都没有工作,甚至一条规则:(!

任何人都可以帮助我,谢谢!

<IfModule mod_rewrite.c>
RewriteEngine on

#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteRule . /index.php [L]
</IfModule>
<IfModule mod_php5.c>
    php_flag magic_quotes_gpc         off
    php_flag magic_quotes_runtime     off
</IfModule>
<IfModule mod_php4.c>
    php_flag magic_quotes_gpc         off
    php_flag magic_quotes_runtime     off
</IfModule>

1 个答案:

答案 0 :(得分:0)

找到了一个有趣的网站:将htaccess转换为nginx配置:

http://winginx.com/en/htaccess

根据自动转换,它被翻译为:

# nginx configuration
location ~ /index.php$ {
}
location / {
    if ($http_host !~ "^www\."){
        rewrite ^(.*)$ https://www.$http_host$request_uri redirect;
    }
    rewrite ^(.*)$ https://$http_host$request_uri redirect;
    if (!-e $request_filename){
        rewrite ^(.*)$ /index.php break;
    }
}

似乎没有转换php模块配置(为通用工具定制的方式)。请告诉我这是否正常。