【问题标题】:RewriteCond [.htaccess]RewriteCond [.htaccess]
【发布时间】:2023-01-25 02:36:16
【问题描述】:

我想知道为什么这个配置在通过 http(端口 80)请求 /api/client 时返回 308。

注意:接收响应的设备是 ARDUINO,他不处理 3XX 响应。

    RewriteCond %{REQUEST_URI} !='/api/client'                    # ....
    #RewriteCond expr "%{REQUEST_URI} -strmatch '/api/client'"    #Doesn't work
    #RewriteCond expr "%{REQUEST_URI} !~/api/"                    #Doesn't work
    #RewriteCond !%{REQUEST_URI} ^/api/client                     #Doesn't work
    #RewriteCond %{REQUEST_URI} !^/api/client                     #Doesn't work

    RewriteCond %{SERVER_PORT} !=443
    RewriteRule ^(.*)$ https://example.com/$1 [R=308,L]

目标是将所有 HTTP 请求(端口 80)重定向到 HTTPS,除了对 /api/client 的请求

【问题讨论】:

    标签: apache .htaccess redirect mod-rewrite


    【解决方案1】:

    目的是将所有 HTTP 请求(端口 80)重定向到 HTTPS,除了对 /api/client 的请求

    使用 THE_REQUEST 变量尝试此规则:

    RewriteEngine On
    
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{THE_REQUEST} !/api/client [NC]
    RewrtieRule ^ http:// %{HTTP_HOST}%{REQUEST_URI} [NE,R=308,L]
    

    THE_REQUEST 变量表示 Apache 从您的浏览器接收到的原始请求,并且在执行其他重写指令后它不会被覆盖。此变量的示例值为GET /index.php?id=123 HTTP/1.1

    确保在清除旧缓存或从新浏览器中对其进行测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-02
      • 2011-09-30
      相关资源
      最近更新 更多