HOWTO: Forzar uso de SSL
Estamos usando Apche mod_ssl:
1. Via programación, usando PHP:
if ( !isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != 'on' ) {
header("Location: " . "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
exit();
}
header("Location: " . "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
exit();
}
Este código se puede poner en cada archivo php que se desee redirigir a SSL, o en un include general. Alternativamente se puede usar HTTP_HOST, o simplemente header('Location: https://example.org/admin/');
2. Via .htaccess, para todo el sitio
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.org/$1 [R,L]
3. Via .htaccess, para algun folder
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} admin RewriteRule ^(.*)$ https://www.example.org/admin/$1 [R,L]
Nota: estas opciones de .htaccess pueden usarse también en la configuración inicial de apache, por ejemplo httpd.conf, usar /admin, las direcciones no son relativas.
4. En VirtualHost de httpd.conf
<VirtualHost 192.168.0.1:80> ServerName www.example.org DocumentRoot /www/example.org/public_html Redirect /admin https://www.example.org/admin </VirtualHost>
CategorySysAdmin