Sometimes you need to force your visitors to use secure connection if they forgot to type https://
in the browser. It can be accomplished by adding the following lines to .htaccess
file located in the root folder of your web site. It will force secure connection for all pages on your web site.
.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]
Michael Ryvkin
Freelance web developer based in Perkasie, Bucks County, PA. I design and develop custom websites and web applications, perform website maintenance and provide technical support for small and medium-sized businesses.
Contact me for a free quote or consultation on your project.
RewriteEngine On
# если запрашиваемый пользователем URL – это не существующий на сервере файл…
RewriteCond %{REQUEST_FILENAME} !-f
# …и не существующая на сервере директория
RewriteCond %{REQUEST_FILENAME} !-d
# перенаправляем запрос пользователя на xxx.php
RewriteRule ^(.*)$ xxx.php [L]