【问题标题】:I need url rewriting conversion from htaccess to NGINX我需要从 htaccess 到 NGINX 的 url 重写转换
【发布时间】:2014-12-12 09:25:12
【问题描述】:

我尝试转换这个 .htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]

到 NGINX

location / {
    try_files $uri $uri/  /index.php?_route=$uri;
}

但不起作用

如果工作,您将在http://test.bktvnews.com/data/menu/footer 上看到 json 文件 http://test.bktvnews.com/data/

【问题讨论】:

  • 我在 Apache 中看到了 _route_=,在 nginx 中看到了 _route=。此外,Apache 仅在没有查询部分时才会重写。而且,仍然显示完整的 nginx 服务器配置。
  • 顺便说一句,nginx 中的$uri/ 开头。
  • 谢谢,我改变了这一点,但仍然无法正常工作你所说的 / 和 $url
  • 他的意思是在 htaccess 中 $1 将是 data/menu/folder,但在 nginx 中 $uri 是 /data/menu/folder - 这可能对您的应用程序很重要。你能告诉更多关于“不起作用”的信息吗?

标签: apache .htaccess nginx


【解决方案1】:

您可以使用此在线工具进行转换。 http://winginx.com/en/htaccess

这是你对 nginx 的 .htaccess

# nginx configuration
location / {
    if (!-e $request_filename){
        rewrite ^/(.)\?$ /index.php?route=$1 break;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-02
    • 2015-11-11
    • 1970-01-01
    • 2017-12-18
    • 2017-06-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多