Come garantire che Apache serve sempre una singola pagina tramite HTTPS?
-
21-09-2019 - |
Domanda
Vorrei reindirizzare tutte le connessioni da htt_p: //www.example.com/abc.html a HTTP_S: //www.example.com/abc.html. Che mod_alias o comandi mod_rewrite avrebbe funzionato per questo? Ho provato:
RewriteEngine on
RewriteCond %{HTTPS} =off
RewriteRule $abc\.html^ https://www.example.com/abc.html [R]
sia in .htaccess e httpd.conf, ma che non funziona. Funziona se la prima stringa nella RewriteRule è qualsiasi altra cosa (come abz.html), ma non se è abc.html. abc.html è un vero e proprio file sul server (non un altro redirect). Opzioni FollowSymlinks è presente nella direttiva directory appropriata.
Molte grazie.
Soluzione
Qualcosa sulla falsariga di quanto segue vi permetterà di reindirizzare le pagine non SSL per le versioni SSL (supponendo che si esegue SSL sulla porta 443):
RewriteEngine on
# Limited redirects
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} ^/abc\.html$ [OR,NC]
RewriteCond %{REQUEST_URI} ^/def\.html$ [OR,NC]
RewriteCond %{REQUEST_URI} ^/ghi\.html$ [NC]
RewriteRule ^/(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
La bandiera [OR] dopo la RewriteCond è letteralmente che, "o", che è il motivo per cui l'ultima condizione non ce l'ha