0
votes

I currently have a Linux Dedicated Server and I would like to 301 Redirect several versions of my domain name (and its files/directories) to the https:// version via .htaccess. My goal is to have ONE version of my domain no matter how it is typed and no matter what file and/or subdirectory is trying to be reached.

What I am seeking...

  1. http:// example.com >> https:// example.com
  2. http:// www.example.com >> https:// example.com
  3. https:// www.example.com >> https:// example.com

Examples of files/directories...

  • http:// example.com/1.jpg >> https:// example.com/1.jpg
  • http:// www.example.com/sub/ >> https:// example.com/sub/
  • https:// www.example.com/sub/1.jpg >> https:// example.com/sub/1.jpg

Notice how everything 301's to https://example.com ?

**Lets pretend I have a completely blank .htaccess file and would like to accomplish this set-up. How should my code look like? I really do not have a .htaccess file and 0 add-ons or customization to my server.

1

1 Answers

1
votes

Add this to your .htaccess in your web root / directory.

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]