I'm working on something that should be really simple but hitting head against the wall second day. The URLs redirect requirements are:
- non-www => www
- non-https => https
/file.html
=>/utilities/template_handler.php?filename=file.html
The problem: when I request https://example.com/file.html
I get r=301 to
https://example.com/utilities/template_handler.php?filename=https://www.example.com/file.html
My .htaccess
:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301]
RewriteRule ^(.*)\.html$ /utilities/template_handler.php?filename=$1.html [NC]
I'm using litespeed webserver but for troubleshooting purpose set up Apache too, the same result. After debug is turned on I see:
strip base: '/' from URI: '/file.html'
Rule: Match 'file.html' with pattern '.*', result: 1
Cond: Match 'on' with pattern 'off', result: -1
Rule: Match 'file.html' with pattern '.*', result: 1
Cond: Match 'domain.com' with pattern '^www\.', result: -1
Source URI: 'file.html' => Result URI: 'https://www.example.com/file.html'
Rule: Match 'https://www.example.com/file.html' with pattern '^(.*)\.html$', result: 2
Source URI: 'https://www.example.com/file.html' => Result URI: '/utilities/template_handler.php?filename=https://www.example.com/file.html'
replace current query string with 'filename=https://www.example.com/file.html'
If I comment out the last rule I have first two requirements processed correctly.
The same error if the request sent to non-www or to www but non-ssl.