With the below rewrites in htaccess, as expected, this HTTPS request is not rewritten:
https://example.com/system/anything
is not re-written to
http://example.com/system/anything
But, unexpectedly, this HTTPS request is rewritten:
https://example.com/preview/anything
is re-written to
http://example.com/index.php/preview/anything
Why is this?
A couple other facts / observations:
/system/
is an actual path on the server. But /preview/
is not an actual path--it's a URL segment that makes sense in the CMS, e.g., /index.php/preview/anything
is how the CMS gets the request for the /preview/anything
URL.
Other non-system URLs do rewrite properly (from HTTPS to HTTP), and properly do get passed to index.php. E.g.,
https://example.com/real
is re-written to
http://example.com/real
Here is the full block of rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Force HTTPS for System URLs
RewriteCond %{REQUEST_URI} ^/system(.*)$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ "https://example.com/$1" [R=301,L]
# Force HTTP for Other URLs, but not: system or preview
RewriteCond %{REQUEST_URI} !^/(system|preview)/(.*)$ [NC]
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ "http://example.com/$1" [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
Any insights into why /preview/
gets the weird treatment?
Added: Note that /preview/anything
is getting a 302
redirect to /index.php/preview/anything
-- and THAT'S a big part of what seems so weird / unexpected. It should not be getting a redirect in the final rule, just a rewrite.