Title: htaccess redirection
Last modified: December 3, 2019

---

# htaccess redirection

 *  Resolved [jwamsterdam](https://wordpress.org/support/users/jwamsterdam/)
 * (@jwamsterdam)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/htaccess-redirection-7/)
 * Hi,
 * I would like to add the following redirections to my website:
    – add trailing
   slash – redirect non-www to www – redirect http to https
 * In my site admin panel, I have configured the site url to [https://www](https://www).
   and at this moment the http is redirected to https. I don’t see this rule in 
   htaccess, so I guess this might be redirected by wordpress or google chrome.
 * I would like to add the following rules:
 *     ```
       #### Force HTTPS://WWW and remove trailing / from files ####
       ## Turn on rewrite engine
       RewriteEngine on
   
       # Remove trailing slash from non-filepath urls
       RewriteCond %{REQUEST_URI} /(.+)/$
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule ^ https://www.example.com/%1 [R=301,L]
   
       # Include trailing slash on directory 
       RewriteCond %{REQUEST_URI} !(.+)/$
       RewriteCond %{REQUEST_FILENAME} -d
       RewriteRule ^(.+)$ https://www.example.com/$1/ [R=301,L]
   
       # Force HTTPS and WWW 
       RewriteCond %{HTTP_HOST} !^www\.(.*)$ [OR,NC]
       RewriteCond %{https} off  
       RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
   
       source: https://www.danielmorell.com/guides/htaccess-seo/redirects/https-www-and-trailing-slash
       ```
   
 * looking at my htaccess, I see the following rewrite conditions at the top of 
   my htaccess file:
 *     ```
       # BEGIN WordPress
       # De richtlijnen (regels) tussen <code>BEGIN WordPress</code> and <code>END WordPress</code> worden
       # dynamisch aangemaakt en zouden enkel aangepast mogen worden via WordPress filters.
       # Elke wijziging aan deze richtlijnen tussen deze markeringen worden overschreven.
       <IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteBase /
       RewriteRule ^index\.php$ - [L]
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule . /index.php [L]
       </IfModule>
       # END WordPress
       ```
   
 * as well as the following code from cache-enaber:
 *     ```
       # BEGIN Cache Enabler
       <IfModule mod_rewrite.c>
           RewriteEngine On
           RewriteBase /
   
           # set blog sub path
           SetEnvIf Request_URI "^(.*)$" SUB_PATH=/wp-content/cache/cache-enabler/
   
           # set Cache Enabler path
           SetEnvIf Request_URI "^(.*)$" CE_PATH=$1
           SetEnvIf Request_URI "^(/)index.php$" CE_PATH=$1
   
           <IfModule mod_mime.c>
               # webp HTML file
               RewriteCond %{ENV:CE_PATH} /$
               RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*
               RewriteCond %{REQUEST_METHOD} !=POST
               RewriteCond %{QUERY_STRING} =""
               RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
               RewriteCond %{HTTP:Accept-Encoding} gzip
               RewriteCond %{HTTP:Accept} image/webp
               RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index-webp.html.gz -f
               RewriteRule ^(.*) %{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index-webp.html.gz [L]
   
               # gzip HTML file
               RewriteCond %{ENV:CE_PATH} /$
               RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*
               RewriteCond %{REQUEST_METHOD} !=POST
               RewriteCond %{QUERY_STRING} =""
               RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
               RewriteCond %{HTTP:Accept-Encoding} gzip
               RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html.gz -f
               RewriteRule ^(.*) %{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html.gz [L]
   
               AddType text/html .gz
               AddEncoding gzip .gz
           </IfModule>
   
           # webp HTML file
           RewriteCond %{ENV:CE_PATH} /$
           RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*
           RewriteCond %{REQUEST_METHOD} !=POST
           RewriteCond %{QUERY_STRING} =""
           RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
           RewriteCond %{HTTP:Accept} image/webp
           RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index-webp.html -f
           RewriteRule ^(.*) %{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index-webp.html [L]
   
           # default HTML file
           RewriteCond %{ENV:CE_PATH} /$
           RewriteCond %{ENV:CE_PATH} !^/wp-admin/.*
           RewriteCond %{REQUEST_METHOD} !=POST
           RewriteCond %{QUERY_STRING} =""
           RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
           RewriteCond %{DOCUMENT_ROOT}%{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html -f
           RewriteRule ^(.*) %{ENV:SUB_PATH}%{HTTP_HOST}%{ENV:CE_PATH}index.html [L]
   
           # wp override
           RewriteCond %{REQUEST_FILENAME} !-f
           RewriteCond %{REQUEST_FILENAME} !-d
           RewriteRule . /index.php [END]
       </IfModule>
       # END Cache Enabler
       ```
   
 * Now I think I have duplicate rewrite rules, which can / should be simplified.
 * But besides that, by adding the rules I have posted at the beginning of this 
   message to the top of my htaccess, I get an error saying: **too many redirects**.
 * Could you help me out setting up the correct htaccess rules, while keep using
   the htaccess static page functionality of cache-enabler?
 * Thank you!
    -  This topic was modified 6 years, 6 months ago by [jwamsterdam](https://wordpress.org/support/users/jwamsterdam/).
    -  This topic was modified 6 years, 6 months ago by [jwamsterdam](https://wordpress.org/support/users/jwamsterdam/).
    -  This topic was modified 6 years, 6 months ago by [jwamsterdam](https://wordpress.org/support/users/jwamsterdam/).

Viewing 1 replies (of 1 total)

 *  Anonymous User 16850768
 * (@anonymized-16850768)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/htaccess-redirection-7/#post-12224854)
 * Adding a trailing forward slash, redirecting an apex domain (e.g. [https://example.com](https://example.com))
   to a www subdomain (e.g. [https://www.example.com](https://www.example.com)),
   and redirecting HTTP to HTTPS is unrelated to the Cache Enabler plugin.
 * The [advanced configuration](https://www.keycdn.com/support/wordpress-cache-enabler-plugin#advanced-configuration)
   for the Cache Enabler plugin is optional and not required.

Viewing 1 replies (of 1 total)

The topic ‘htaccess redirection’ is closed to new replies.

 * ![](https://ps.w.org/cache-enabler/assets/icon.svg?rev=2442383)
 * [Cache Enabler](https://wordpress.org/plugins/cache-enabler/)
 * [Support Threads](https://wordpress.org/support/plugin/cache-enabler/)
 * [Active Topics](https://wordpress.org/support/plugin/cache-enabler/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cache-enabler/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cache-enabler/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: Anonymous User 16850768
 * Last activity: [6 years, 6 months ago](https://wordpress.org/support/topic/htaccess-redirection-7/#post-12224854)
 * Status: resolved