Kompx.com or Compmiscellanea.com

HTTP to HTTPS redirect in .htaccess

Web servers : Apache + nginx

Redirecting from HTTP to HTTPS, when the web server serving the pages is behind a load balancer or reverse proxy. Server configuration:

  • Apache + nginx;
  • SSL is enabled;
  • SSL-certificate is purchased, approved and installed.

That is, everything is up and running. So it is just the HTTP to HTTPS redirection that is left to get ready and start up. Directives for .htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]

RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{HTTP:X_FORWARDED_PROTO} !https [NC]

RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

HTTP to HTTPS redirect

-- Enable runtime rewriting engine:

RewriteEngine On

-- If domain name has no www:

RewriteCond %{HTTP_HOST} !^www\. [NC]

-- Then replace it with domain with www:

RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

-- If HTTPS is not present:

RewriteCond %{HTTP:X_FORWARDED_PROTO} !https [NC]

-- Then replace domain without HTTPS with domain with HTTPS:

RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

Notes

1. X_FORWARDED_PROTO may instead be called X-Forwarded-Proto or even else. The point is to obtain the information from a load balancer or reverse proxy on the original request it gets. Load balancers or reverse proxies may provide the web server with this info and a header named X_FORWARDED_PROTO or X-Forwarded-Proto or else may be sent, holding the protocol string. It is most often so, but not always. So it should probably be determined by practice how to get the protocol string in a particular case.

2. The other way is just to set the environment variable (if it is suitable for the given web server):

SetEnvIf X_FORWARDED_PROTO https HTTPS=on

Then directives for .htaccess file are to be like this:

RewriteEngine On

SetEnvIf X_FORWARDED_PROTO https HTTPS=on

RewriteCond %{HTTP_HOST} !^www\. [NC]

RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{HTTP:HTTPS} !on [NV]

RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

3. Apache Module mod_rewrite docs: http://httpd.apache.org/docs/current/mod/mod_rewrite.html


Aliosque subditos et thema

 

Windows console applications

 

Some time ago text-based applications were the only form of software of average end user computer experience. As well as after the graphical user interface programs started to become widespread, console applications used to retain their strong positions. But gradually GUI software virtually superseded text-based applications in daily use of the average end user. However, even now there are console programs that can more or less compete with software of graphical user interface, be useful for the average user to solve various problems and fulfill numerous tasks on modern computers. Windows console applications. File managers Windows console applications. Multimedia Windows console applications. Web browsers Windows console applications. Text editors Besides file managers, multimedia programs, text editors, web browsers, there are plenty of other text-based programs and utilities for use under Windows: both standalone and those included in MS Windows distributions. For example, ipconfig and netstat for work with network, Windows built-in FTP client useful for some tasks, CommandBurner for command line burning CD / DVD or cdburn with dvdburn from Windows Server 2003 Support Tools for the same, etc.

Imapsync IMAP migration under Windows

 

Migrating an IMAP e-mail box from one IMAP server to another under Windows [ 1 ] [ 2 ] by means of imapsync: Copying an e-mail box with all its contents and keeping its folder structure; The e-mail box is hosted at a web hosting company's server and transfered to a common Yandex Mail (not Yandex Mail for Domain); Both IMAP servers support SSL. The process is done in three steps: test run, migrating folder structure, migrating e-mails. Test run Content of imapsync-test.bat: .\imapsync.exe ^ --host1 imap.domain.ru --user1 email1@domain.ru --password1 "password1" ^ --host2 imap.yandex.ru --user2 email2@yandex.ru --password2 "password2" ^ --ssl1 --ssl2 --sslargs1 SSL_verify_mode=0 --sslargs2 SSL_verify_mode=1 ^ --skipheader "^(?!Message-Id)" ^ --automap ^ --regextrans2 "s/^INBOX\.(.+)/$1/" ^ --addheader ^ --justfolders ^ --dry @PAUSE Note: the caret character ( ^ ) at the end of line means "this command continues on the next line". It allows to break long command with many options into several parts to put them in several lines for better readability. This step is meant for testing if imapsync may be run at all, if it can connect to both e-mail boxes and can read the basic structure of the first one. Imapsync runs without actually doing anything, just printing what would have been done without the --dry option. Adding --justfolders is to make testing faster, as imapsync does its job only for folders then. A log file with full details for each run is placed into the LOG_imapsync folder. Migrating folder structure Content of imapsync-folders.bat: .\imapsync.exe ^ --host1 imap.domain.ru --user1 email1@domain.ru --password1 "password1" ^ --host2 imap.yandex.ru --user2 email2@yandex.ru --password2 "password2" ^ --ssl1 --ssl2 --sslargs1 SSL_verify_mode=0 --sslargs2 SSL_verify_mode=1 ^ --skipheader "^(?!Message-Id)" ^ --automap ^ --regextrans2 "s/^INBOX\.(.+)/$1/" ^ --addheader ^ --justfolders @PAUSE This step reproduces the folder structure of the e-mail box being migrated in the one it is being migrated to. Migrating e-mails Content of imapsync-emails.bat: .\imapsync.exe ^ --host1 imap.domain.ru --user1 email1@domain.ru --password1 "password1" ^ --host2 imap.yandex.ru --user2 email2@yandex.ru --password2 "password2" ^ --ssl1 --ssl2 --sslargs1 SSL_verify_mode=0 --sslargs2 SSL_verify_mode=1 ^ --skipheader "^(?!Message-Id)" ^ --automap ^ --regextrans2 "s/^INBOX\.(.+)/$1/" ^ --addheader @PAUSE Now e-mails are being copied.