Force HTTPS using only HTACCESS in SYMFONY

佐手、 提交于 2019-11-28 01:44:54

问题


We have a Symfony 1.4 project and are looking to force https for all pages in a symfony application using only the htaccess file. I know there are ways to do using filters but I want to know if its possible to do without that first?

Here is the .HTACCESS file I currently am using but isn't working as expected...

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteCond %{REQUEST_FILENAME} !-f

I've also tried without success:

RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

I am sure there is some quirk I am missing in doing this with Symfony as this is an easy task to do straight away. Any ideas gents?


回答1:


Regarding a previous answer, try:

RewriteCond %{SERVER_PORT} !^443$
RewriteRule .? https://%{HTTP_HOST}%{REQUEST_URI} [R,L]


来源:https://stackoverflow.com/questions/10703206/force-https-using-only-htaccess-in-symfony

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!