【问题标题】:HTACCESS 2 NGINX Rule,any can help me?HTACCESS 2 NGINX 规则,有什么可以帮助我的吗?
【发布时间】:2014-11-08 02:43:56
【问题描述】:

我有一个站点需要从 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>

【问题讨论】:

标签: apache .htaccess mod-rewrite nginx


【解决方案1】:

找到一个有趣的网站来完成这项工作:将 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 模块配置未转换(为通用工具定制的方式)。请让我知道这是否工作正常。

【讨论】:

    猜你喜欢
    • 2015-06-29
    • 1970-01-01
    • 2011-04-16
    • 1970-01-01
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 2020-05-29
    • 1970-01-01
    相关资源
    最近更新 更多