I’m trying to implement the HTTPS suggestion from the security page for my panel. The .htaccess rules are defeating me though. Does anyone have any tips on what that rule would generally look like, and where it would go?
This is what I have so far, that would replace this section of the default rules, but it’s not redirecting properly. Also, I’m running in a subdirectory on the server.
# make panel links work
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^panel/(.*) https://example.com/subdirectory/panel/index.php [L]
The front-end of the site still works fine. Thanks for any guidance.
Do you have access to your apache conf files? Using the .htaccess file is only your second best option.
I don’t think you need to touch the original panel rewrite rules, and just add this bit at the top (but not tested):
RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e. http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context
Unfortunately I can’t get into the apache conf files.
Thanks for the wiki reference. I tried adding those 2 directives above and below my RewriteBase rule and it kept sending me to the root directory (above my kirby install).
When I have been able to get something to work, sometimes the images won’t load, and the CSS will never load. I imagine this has something to do with blocking resources that come from http instead of https?
I’ll keep testing… but if you have any more ideas…
Thanks for the url idea. I’m wondering if the complication is arising from the fact that I’m running everything in a subdirectory–kirby and the whole site.
Finally looked at my site > config file so I could set the url like you suggested. I found some old code in there I had left from when I was trying to get my installation of Kirby running in a subdirectory. This was the bad code:
c::set('url', 'http://example.com/subdirectory');
So I was forcing it to go back to http. Unbelievable. Thanks for all your help!!!
FWIW, here are the htaccess rules that worked for me. I’m running the entire site in a subfolder.
RewriteEngine on
# make sure url not already https
RewriteCond %{HTTPS} !=on
# send panel traffic to https and the subfolder
RewriteRule ^/?panel/(.*) https://%{SERVER_NAME}/mySubfolderName/panel/$1 [R,L]
# rewrite base
RewriteBase /mySubfolderName
...