starlight22
starlight22

Reputation: 21

redirect all url and folders from http to https in htaccess file

Domain redirects from http to https in my htaccess file, but none of my urls and folders will redirect from http to https. Example: www.example.com/example.html or www.example.com/folder/example.html will not redirect from http to https

What is the rewrite rule for the htaccess file to redirect all urls and all folders from http to https?

Upvotes: 2

Views: 4009

Answers (1)

Matt S
Matt S

Reputation: 1757

# add trailing slash to directories and force SSL
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !(/$) 
RewriteCond %{SERVER_PORT} 80 
RewriteRule (.*) https://www.example.com/$1/ [R=301,L]

# And for the files
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

That's what we have

Upvotes: 5

Related Questions