簡體   English   中英

RewriteCond [.htaccess]

[英]RewriteCond [.htaccess]

我想知道為什么這個配置在通過 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 的請求

目標是將所有 HTTP 請求(端口 80)重定向到 HTTPS 除了對/api/client的請求

使用THE_REQUEST變量嘗試此規則:

RewriteEngine On

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

THE_REQUEST變量表示 Apache 從您的瀏覽器收到的原始請求,並且在執行其他重寫指令后它不會被覆蓋。 此變量的示例值為GET /index.php?id=123 HTTP/1.1

確保在清除舊緩存或從新瀏覽器中對其進行測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM