linux - Redirecting HTTP to HTTPS. What's the best method? -
i've searched high , low answer question appreciated.
i have linux server apache, , i'm trying understand specific methods available accept http requests , forward or redirect them https on same server.
i need know why 1 method might better another, why choose specific method on another? quite important me understand.
thanks help
with apache+php there couple different ways: server configuration or php code. benefits of performing kind of check in server configuration applied everywhere, or on per-directory basis without having change php on every page in folder or on site. server configuration provides faster runtime.
server configuration
using mod_rewrite, add following lines vhost config file:
rewriteengine on rewritecond %{https} off rewritecond %{server_name} (.*) rewriterule (.*) https://%1/$1 [r=301,l]
obviously, mod_rewrite must enabled on server work. apache's mod_rewrite documentation has more details.
php code
as others have mentioned, php provides header
function can used set location
http response header, , redirect client https. not require access server configuration or mod_rewrite.
Comments
Post a Comment