Answers.Body: <p>Been using this one for years, works great:</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
      RewriteEngine On
  
      # ========================================= #
      # Force website to use "www"
      RewriteCond %{HTTP_HOST} ^example.com [NC]
      RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
      # ========================================= #
  
      # ========================================= #
      # Force website to use "https"
      RewriteCond %{HTTPS} off
      RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
      # ========================================= #
  
      # ========================================= #
      # Send would-be 404 requests to Craft
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
      RewriteRule (.+) index.php?p=$1 [QSA,L]
      # ========================================= #
  
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>This one <em>adds</em> <code>www</code>, but it's simple to reverse that (as you do in your original example).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-08T04:22:13.270Z
Answers.LastActivityDate: 2017-09-08T04:22:13.270Z
Answers.UserDisplayName: Lindsey D
Answers.Body: <p>Since you mentioned in an earlier post that you are performance-minded, this might interest you: <a href="https://nystudio107.com/blog/stop-using-htaccess-files-no-really" rel="nofollow noreferrer">Stop using .htaccess files! No, really.</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-08T04:20:02.307Z
Answers.LastActivityDate: 2017-09-08T04:20:02.307Z
Answers.UserDisplayName: andrew.welch
Body: <p>I am looking at shaving www. and enforcing https on the entire site without a plugin.  All along removing the index.php.</p>
  
  <p>Here is my .htaccess file, it works but is it optimized.  If you have any suggestions on how to condense or streamline would like to hear or see an example please. Thanks!</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  
  RewriteEngine On
  
  # Remove WWW and SSL enforce
  RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
  RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
  
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)/$ /$1 [L,R=301]
  # Send would-be 404 requests to Craft
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
  RewriteRule (.+) index.php?p=$1 [QSA,L]
  
  &lt;/IfModule&gt;
  </code></pre>
  
Tags: <redirect><htaccess><apache>
Title: Anyone with a tricked out .htaccess file
ThreadText: # Anyone with a tricked out .htaccess file
  
  (Asked by: username_0 on 2017-09-08)
  
  I am looking at shaving www. and enforcing https on the entire site without a plugin. All along removing the index.php.
  
  Here is my .htaccess file, it works but is it optimized. If you have any suggestions on how to condense or streamline would like to hear or see an example please. Thanks!
  
  ```
  <IfModule mod_rewrite.c>
  
  RewriteEngine On
  
  # Remove WWW and SSL enforce
  RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
  RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
  
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)/$ /$1 [L,R=301]
  # Send would-be 404 requests to Craft
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
  RewriteRule (.+) index.php?p=$1 [QSA,L]
  
  </IfModule>
  
  ```
  
  **Tags:** redirect, htaccess, apache
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2017-09-08. Score: 5 | Accepted answer
  
  Been using this one for years, works great:
  
  ```
  <IfModule mod_rewrite.c>
      RewriteEngine On
  
      # ========================================= #
      # Force website to use "www"
      RewriteCond %{HTTP_HOST} ^example.com [NC]
      RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
      # ========================================= #
  
      # ========================================= #
      # Force website to use "https"
      RewriteCond %{HTTPS} off
      RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
      # ========================================= #
  
      # ========================================= #
      # Send would-be 404 requests to Craft
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
      RewriteRule (.+) index.php?p=$1 [QSA,L]
      # ========================================= #
  
  </IfModule>
  
  ```
  
  This one *adds* `www`, but it's simple to reverse that (as you do in your original example).
  
  
  ---
  
  ### Answer by username_2 on 2017-09-08. Score: 3
  
  Since you mentioned in an earlier post that you are performance-minded, this might interest you: [Stop using .htaccess files! No, really.](https://nystudio107.com/blog/stop-using-htaccess-files-no-really)
  
  
  ---
  
  