0

Note: I cannot be root on example.com, so editing httpd.conf isn't an option.

I want anything from http://example.com to redirect to be https and including the slash directory. This is an example of the problem. The same problem if it is http://www... or http://example.com...

If the URL looks like this:

http://www.example.com/suggestions

It incorrectly redirects to the home page:

https://www.example.com/index.php

When the desired result is for it to redirect to here:

https://www.example.com/suggestions

Here is the .htaccess code I'm using:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
Edward_178118
  • 895
  • 4
  • 14
  • 30

1 Answers1

1

As far as I can tell is you are aming at forcing to use https on all request - right?

Quick Google search gave me:

RewriteEngine On 
RewriteCond %{HTTPS}  !=on 
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

A quick breakdown of what it means:

RewriteCond tells this applies to all requests which is not called using HTTPS.

Two things goes on in the RewriteRule:

1) /?(.*) says it has to match everything in the path, which is then stored in the built in variable $1.

2) %{SERVERNAME} is a built in variable referring to servername (www.example.com in your case).

So RewriteRule basically says: Match everything in the path and redirect to its HTTPS counterpart on the same domain.

  • Also... the OP states that "It incorrectly redirects to the home page: `https://www.example.com/index.php`" - this is consistent with having put the redirect directive in the wrong place in the `.htaccess` file (ie. _after_ the Joomla front-controller). These redirect directives need to go near the top of the `.htaccess` file and, importantly, _before_ the Joomla front-controller. – MrWhite Oct 16 '19 at 14:44
  • @MrWhite I have moved the code I provided to the top part of the .htaccess and it behaved the same way. What are you referring to as the Joomla front-controller in an .htaccess file? – Edward_178118 Oct 17 '19 at 02:28
  • @Edward_178118 "the code I provided" - You will certainly need code like @Lasse provided in his answer. The code you have in the question is not an HTTP to HTTPS redirect (in fact, the code as posted in the question is not anything - it would result in a redirect loop if executed). Joomla uses a front-controller pattern in order to route URLs through the CMS. This is achieved by internally rewriting all requests (for non-static resources) to `index.php` (the "front-controller"). Your "redirect" needs to go before the directives that rewrite the request to `index.php`. – MrWhite Oct 17 '19 at 10:36
  • And some more Googling: https://www.joomlart.com/tutorials/joomla-tutorials/how-to-use-ssl-in-a-joomla-site. Here you will get a complete tutorial in how to setup Joomla with HTTPS everywhere. – Lasse Michael Mølgaard Oct 20 '19 at 11:40