2

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:

  1. 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.
  2. Force switch all incoming connections to use HTTPS instead of HTTP
  3. Force everything within Joomla to use HTTPS
  4. 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:

  1. Can I get some help crafting the .htaccess file to redirect to secured joomla?
  2. 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?
  3. 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?
  4. 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.

6
  • Your hosting provider should offer the ability to map a domain to a specific directory. This normally happens when you create a domain on your hosting account
    – Lodder
    Commented Dec 4, 2020 at 20:03
  • "HTTPS .... is not available on this server." - Do you have a SSL certificate installed that covers both the www subdomain and domain apex? ie. the site needs to be accessible over HTTPS (without browser warnings) before any attempt can be made to force/redirect to HTTPS.
    – MrWhite
    Commented Dec 5, 2020 at 1:09
  • I am my hosting provider in that I own the Synology disk station the site is running on. The standard solution for mapping a domain to a subdirectory in Synology is virtual hosts, but for some reason this works with index.html files but NOT index.php files like Joomla uses and I am not sure why. Also yes, I have an HTTPS certificate for the domain example.com and www.example.com (what is a domain apex?) and if I manually type https into the URL bar any page in my Joomla site will switch to https without issue.
    – Nathanael
    Commented Dec 5, 2020 at 1:44
  • The domain "apex" is the registered domain (without any subdomains), eg. example.com.
    – MrWhite
    Commented Dec 5, 2020 at 2:05
  • 1
    Have you tried with adding this line to .htaccess: DirectoryIndex first.html index.htm index.html index.php. This should handle the problem of using index.php as index page as it is alternating the directory index file.
    – Zollie
    Commented Dec 5, 2020 at 18:26

1 Answer 1

1

For my environments I use this piece of code in the .htaccess of the root directory, in your case /web

RewriteEngine On

# External Redirect adding leading www to domain or any subdomain if missing
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Internally Rewrite requests to redirect the default domain to the folder you want.
rewriteCond %{http_HOST} ^www\.yourdomain\.com\.au$
rewriteRule (.*) /joomladirectory/$1 [L]

And in the configuration.php I use the livesite= to hold the url, as you have, and public $force_ssl = 2;

I also use the default Joomla supplied .htaccess as supplied in the installation folder, /web/joomla in your example.

I am not familiar with the Synology Disk Station to know if there are going to be other issues, however I install all my Joomla installations into sub directories of the root directory and have been doing this on various hosts for more than 10 years with no compatibility issues so I think it should work for you.

If you want to ignore other directories to exclude them from being changed you can insert this line before the last rewriteRule, #rewriteCond $1 !^ignoredirectory/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.