Force SSL using .htaccess and mod_rewrite

.htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

If you want to force secure connection only in certain directory (for example /secure), use this code instead.

.htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^secure
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Comments

  1. RewriteEngine On
    # если запрашиваемый пользователем URL – это не существующий на сервере файл…
    RewriteCond %{REQUEST_FILENAME} !-f
    # …и не существующая на сервере директория
    RewriteCond %{REQUEST_FILENAME} !-d
    # перенаправляем запрос пользователя на xxx.php
    RewriteRule ^(.*)$ xxx.php [L]

Leave a Reply to vestiyuga Cancel reply

(optional)

This site uses Akismet to reduce spam. Learn how your comment data is processed.