Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

RewriteCond [.htaccess]

I would like to know why is this configuration returning me a 308 when requesting to /api/client via http (port 80).

Note: The device that receive the response is an ARDUINO, he doesnt handle the 3XX responses.

    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]

The objetive is to redirect all the HTTP request (Port 80) to HTTPS except the requests to /api/client

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The objective is to redirect all the HTTP request (Port 80) to HTTPS except the requests to /api/client

Try this rule with THE_REQUEST variable:

RewriteEngine On

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

THE_REQUEST variable represents original request received by Apache from your browser and it doesn’t get overwritten after execution of other rewrite directives. Example value of this variable is GET /index.php?id=123 HTTP/1.1

Make sure to test it after clearing old cache or from a new browser.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading