Search code examples
xmlstring.htaccessurl-rewritingcontain

htaccess rewrite to https if not xml file and not containing display in request URI


How to create a htaccess rewrite rule to https for non xml file request and when the request URI not containing string "display"?

I've tried the following but this doesn't work:

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !xml [NC,OR]
RewriteCond %{REQUEST_URI} !display [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Thank you.


Solution

  • Use:

    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} !xml [NC]
    RewriteCond %{REQUEST_URI} !display [NC]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
    

    Because it's ANDand not OR