1

I just created my first encrypted (https) site. I was advised that it might be best to use https in my "canonical" links and use my .htaccess file to redirect traffic to the new https links. I found the code for that task here.

RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

It works fine online. The problem is that it messes up my local sites. It isn't a huge problem; I could simply make separate .htaccess files - one for online and one for local use. But that would be a minor pain, so I wondered if there's another solution.

My local pages won't display at https, so I wondered if there's a way to tell my .htaccess file to make this new rule apply online only.

EDIT:

Maybe I should reword my post to ask how YOU handle this situation. I'm not even sure if .htaccess is the only player here...

Community
  • 1
  • 1
WordBear
  • 177
  • 6
  • I would exclude your `.htaccess` file from your local copy (`exclude` or `.gitignore` all together) – Dominik May 05 '16 at 02:36

1 Answers1

1
  1. don't use the .htaccess file on your local host.
  2. encrypt your local host. it's really easy to make a self-signed certificate with openssl for free.
Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167