Setting up a Joomla site on Apache 2.4 on a Synology Disk Station. Joomla is unavoidably installed in a subdirectory of the web root (/web/joomla) and unfortunately do not have access to the Apache httpd.conf file to reset the DocumentRoot variable.
My ultimate goals for the site are as follows:
- Make the /joomla subdirectory appear to be the root of the site, i.e. anybody visiting example.com will be shown the page at /web/joomla/index.php but still see example.com in the URL bar.
- Force switch all incoming connections to use HTTPS instead of HTTP
- Force everything within Joomla to use HTTPS
- Develop a strategy for SEF URLS within Joomla
My current strategy relies on setting the joomla configuration.php variable $live_site = 'https://example.com';
and using an the following .htaccess file in the web root (/web):
RewriteEngine on
RewriteBase /
# Rewrites all URLS without joomla in them
RewriteCond %{REQUEST_URI} !^/joomla/
# Rewrites all URLS with example in them
RewriteCond %{HTTP_HOST} ^(www\.)?example\.
# Rewrite all those to insert /joomla
RewriteRule ^(.*)$ /joomla/$1 [L]
# This works SOME of the time to redirect to https
Header always set Content-Security-Policy "upgrade-insecure-requests;"
# If a request tries to access /joomla directly, redirect it to its secured canonical version
RewriteCond %{THE_REQUEST} joomla/
RewriteRule ^joomla/(.*) http://example.com/$1 [R=301,L]
This seems to work some of the time in Chrome, redirecting to the Joomla installation and switching to https, and NEVER works in Firefox. I had to remove the default .htaccess file in joomla entirely to avoid 500 errors when accessing the joomla site. I have seen other examples online using RewriteCond %{HTTPS} !=on
or RewriteCond %{SERVER_PORT} 80
together with various RewriteRule
commands but I am not sure how to to combine these commands with the existing URL rewriting conditions I am sure I am not using best practice.
My questions are these:
- Can I get some help crafting the .htaccess file to redirect to secured joomla?
- Do I need another .htaccess file in the Joomla subdirectory to assist the above rewriting rules or hand over control of forcing HTTPS to Joomla?
- When I set the joomla global configuration to "force HTTPS: entire site" I get the error
HTTPS has not been enabled as it is not available on this server. HTTPS connection test failed with the following error: Connection timed out after 10000 milliseconds
why is this? - For crafting SEF URLS, will I need to do most of that work in .htaccess within the joomla subdirectory?
I greatly appreciate any help or documentation of how others have solved these problems. I am sure I am not the first.
example.com
..htaccess
:DirectoryIndex first.html index.htm index.html index.php
. This should handle the problem of usingindex.php
as index page as it is alternating the directory index file.