我试过但没有结果,这是我的.htaccess
。
...
RewriteCond %{HTTP_HOST} ^exampe\.com$ [NC]
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.bmp)$
RewriteRule ^(.*)$ https://www.exampe.com/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.bmp)$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
...
当我尝试http://example.com/image.jpg
时,它会在https://example.com
答案 0 :(得分:2)
您可以根据THE_REQUEST
:
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !\.(png|jpg|gif|jpeg|bmp)
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} \.(png|jpg|gif|jpeg|bmp)
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
确保在新浏览器中进行测试,以避免旧的浏览器缓存。
答案 1 :(得分:2)
让Symfony在app/config/security.yml
security:
# ...
access_control:
# Force images to use HTTP
- { path: \.(png|jpg|gif|jpeg|bmp)$, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: http }
# Force everything else on HTTPS
- { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
您可以在文档中详细了解它: