【问题标题】:zcart nginx configuration + htaccess conversionzcart nginx配置+htaccess转换
【发布时间】:2019-05-19 07:22:35
【问题描述】:

请帮我将 zcart 应用程序的 htaccess 规则转换为 nginx 配置。请看下面的htaccess。

<IfModule mod_rewrite.c>

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

谢谢

【问题讨论】:

    标签: laravel apache .htaccess nginx


    【解决方案1】:

    假设您已经配置了配置的 FastCGI 部分,让我们尝试一下:

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]
    

    可以转换成nginx配置为

    location ~ ^(.+)/$ {
        if (!-d $request_filename) {
            return 301 $1;
        }
        # else this is a directory, will be processed via index file in this directory by default
    }
    

    或(相同的结果)

    location ~ ^(.+)/$ {
        if (!-d $request_filename) {
            rewrite ^(.*)/$ $1 permanent;
        }
        # else this is a directory, will be processed via index file in this directory by default
    }
    

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    

    将由主 location 块中的单个 try_files 指令处理:

    location / {
        try_files $uri $uri/ /index.php;
    }
    

    最后,

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    

    nginx.conf 中不需要额外的配置,因为$_SERVER[HTTP_AUTHORIZATION] 变量将在设置HTTP Authorization 标头时自动附加到$_SERVER 数组(如果您的php-fpm 配置正确)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-25
      • 2021-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-05
      • 1970-01-01
      相关资源
      最近更新 更多