processwire/processwire-requests

htaccess improvement: redirect to www. and https in a single request

Opened this issue · 0 comments

jjozsi commented

To improve the performance when both www. and https:// redirection required, I combine them in a single step as follows:

  # 13D. Redirect to https AND www. in a single request
  RewriteCond %{HTTPS} off [OR]  
  RewriteCond %{HTTP_HOST} !^www\.  
  RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$  
  RewriteRule .* https://www.%1%{REQUEST_URI} [L,NE,R=301]

Having two redirections wastes valuable server time for no reason, having this option in some form in the Processwire htaccess.txt template could prove helpful.
This has been working well for me over the last couple of years but I have to add it in every time I upgrade the core and htaccess file.