0

I just installed SSL certificate on the server.

Current URL: www.example.com

Current working htaccess file:

RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule ^(.*)$ public/ [L]

it is redirecting to public/index.php.

but problem is when I am adding HTTPS code in htaccess then this public/index.php is not working.

RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^example\.com$ [OR] 
RewriteCond %{HTTP_HOST} ^www\.example\.com$ 
RewriteRule ^/?(.*) https://www.example.com/$1 [R] 

When I am removing public redirection part then HTTPS is working but not pointing to public/index.php.

How can I combine these rules so it will redirect to public/index.php with https url.

PS: public/htaccess

ReWriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

Please help!

Thank You

NDesai
  • 1,741
  • 2
  • 12
  • 16

1 Answers1

1

You can use PHP to redirect to your HTTPS website:

if(empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off"){
    $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: ' . $redirect);
    exit();
}

From: Redirecting from HTTP to HTTPS with PHP

However, this piece of code needs to be included on every page, or include it in a PHP file that is included in all other files.

Spoody
  • 2,852
  • 1
  • 26
  • 36
  • I'll remove the .htaccess part I'm not an "expert" in using the .htaccess, I hope one of the folks can post an answer with .htaccess method or simply update my answer. – Spoody Oct 14 '17 at 21:08