我有一个域名,例如foo.com。
我希望所有指向foo.com的流量都重定向到HTTPS,但所有以foo.com/assets /
开头的URL:s除外我可以在.htaccess或apache conf文件中执行此操作吗?
我正在运行带有serverpilots autoSSL的Ubuntu 16.04.5
当前的.haccess文件
RewriteEngine on
# Redirect everything that starts with foo.com/play to http
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} ^/play/$ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect everything that DOESN'T start with foo.com/play to https
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} !^/play/$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Below is old configuration that hasn't anything to do with this question
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.php?cat=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\S-]+)/([\S-]+)/?$ ?cat=$1&page=$2 [QSA]
这是上面的工作方式
http://foo.com>重定向到https://foo.com
http://foo.com/test>不重定向到https(但应该重定向)
https://foo.com/play/test.jpg>不重定向到http(但应该重定向)