apache重写规则,将https更改为特定文件的http请求



所有传入的http://流量都更改为https://www.example.com我想为特定的文件请求启用http,例如http://www.example.com/crossdomain.xml

以下是我当前的重写规则:-

    RewriteEngine On
      # change https to http for specific file called "crossdomain.xml"
    RewriteCond %{REQUEST_URI} ^/crossdomain.xml
    RewriteRule ^/?(.*) http://%{SERVER_NAME}/crossdomain.xml
      # change https to http for specific url/dir access called "/speedtest/"
    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} ^/speedtest
    RewriteRule ^/?(.*) http://%{SERVER_NAME}%/speedtest [L,R=301]
    #rewirte all traffic to https excepth the /speedteset and /crossdomain.xml
    RewriteCond %{HTTPS} !on
    RewriteCond %{REQUEST_URI} !^/speedtest/
    RewriteCond %{REQUEST_URI} !^/crossdomain.xml
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

感谢

添加RewriteCond%{HTTPS}ON后,重写规则在中起作用

    RewriteEngine On
    RewriteCond %{HTTPS} ON    #added this condition to get it working
    RewriteCond %{REQUEST_URI} ^/crossdomain.xml
    RewriteRule ^/?(.*) http://%{SERVER_NAME}/crossdomain.xml
    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} ^/speedtest
    RewriteRule ^/?(.*) http://%{SERVER_NAME}%/speedtest [L,R=301]

    RewriteCond %{HTTPS} !on
    RewriteCond %{REQUEST_URI} !^/speedtest/
    RewriteCond %{REQUEST_URI} !^/crossdomain.xml
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

最新更新