【问题标题】:htaccess rewrite to nginx config not workinghtaccess 重写到 nginx 配置不起作用
【发布时间】:2017-07-25 16:49:47
【问题描述】:

我在使用 nginx 转换 appache .htaccess 文件时遇到问题。

.htaccess 文件

<ifModule mod_rewrite.c>
    Allow from 127.0.0.1

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteRule ^index(|/)$ index.php
    RewriteRule ^logout(|/)$ logout.php
    RewriteRule ^keeping/([^/.]+)(|/)$ keeping.php?s=$1
</ifModule>

我的转化:

location / {
    if (!-e $request_filename){
        rewrite ^/index(|/)$ /index.php;
    }
}
location /logout {
    rewrite ^/logout(|/)$ /logout.php;
}
location /kyhsadminpanel {
    rewrite ^/keeping/([^/.]+)(|/)$ /keeping.php?s=$1;
}

没用。

对于诸如 /kyhsadminpanel/keeping/index 之类的 url,它总是显示“404 not found” 和/kyhsadminpanel/keeping/news...

【问题讨论】:

    标签: apache .htaccess mod-rewrite nginx


    【解决方案1】:

    您可能需要注明您使用过:https://winginx.com/en/htaccess

    我倾向于使用:https://timmehosting.de/htaccess-converter

    这是他们的结果。

    if (!-d $request_filename){
        set $rule_0 1$rule_0;
    }
    if (!-f $request_filename){
        set $rule_0 2$rule_0;
    }
    if ($rule_0 = "21"){
        rewrite ^/index(|/)$ /index.php ;
    }
    rewrite ^/logout(|/)$ /logout.php ;
    rewrite ^/keeping/([^/.]+)(|/)$ /keeping.php?s=$1 ;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-16
      • 2014-08-09
      • 1970-01-01
      • 1970-01-01
      • 2021-10-21
      • 2017-02-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多