-1

I have an .htaccess file the includes some rewrites that are doing a couple of things, which is working fine. It looks like this:

<IfModule mod_rewrite.c>

Options +FollowSymLinks

RewriteEngine On

# Removes .php ending from path
# ---------------

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]

# Services & Knowledgebase rewrites
# ---------------

RewriteRule ^services/([a-zA-Z0-9-/]+)/([a-zA-Z0-9-/]+)$ /services.php?cat=$1&s=$2 [L]
RewriteRule ^services/([a-zA-Z0-9-/]+)$ /services.php?service=$1 [L]

RewriteRule ^knowledge-base/([a-zA-Z0-9-/]+)/([a-zA-Z0-9-/]+)$ /knowledge-base.php?cat=$1&s=$2 [L]
RewriteRule ^knowledge-base/([a-zA-Z0-9-/]+)$ /knowledge-base.php?cat=$1 [L]

</IfModule> 

I have now added SSL to the site, and need to force HTTPS for the entire site. I have tried adding the following to my .htaccess:

# Force HTTPS
# ---------------

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Just after the RewriteEngine On statement, however when I try example.com, the url remains as example.com and I get the following:

Not Found

The requested URL / was not found on this server.

If I go to https://example.com it works perfectly.

How do I force the https correctly, while retaining my other rewrite rules?

Thanks for any help

Mike

Community
  • 1
  • 1
Mike Harrison
  • 1,020
  • 2
  • 15
  • 42
  • Duplicate topic. https://stackoverflow.com/questions/8371/how-do-you-redirect-https-to-http/39074632#39074632 – sys0dm1n Nov 10 '17 at 12:17
  • Hi - I don't think it is a duplicate. That post is about forcing **to** http from https, and does not include anything about working with additional rewrites. – Mike Harrison Nov 10 '17 at 12:58

1 Answers1

1

Here's what I usually use:

RewriteCond %{HTTPS} !=on
RewriteCond %{ENV:HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

Never ran into any issues with that.