Skip to content

Instantly share code, notes, and snippets.

@Garconis
Created August 24, 2019 05:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Garconis/0e3d748dd248ca1e614df007ead0599c to your computer and use it in GitHub Desktop.
Save Garconis/0e3d748dd248ca1e614df007ead0599c to your computer and use it in GitHub Desktop.
Cloudways | .htaccess rewrite URL to HTTPS with WWW
# Cloudways force HTTPS with WWW
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# BEGIN WordPress
<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
Options All -Indexes
# Block Attempts to Enumerate WordPress Users
RewriteCond %{REQUEST_URI} !^/wp-admin [NC]
RewriteCond %{QUERY_STRING} ^author=\d+ [NC,OR]
RewriteCond %{QUERY_STRING} ^author=\{num
RewriteRule ^ - [L,R=403]
@Garconis
Copy link
Author

Garconis commented Aug 24, 2019

You should add both www and non-www domains in Domain Management section in your application. After that, remove the existing rules for HTTPS redirections and add the following rules in the beginning of your application's .htaccess file:

Make sure to replace example.com with your domain name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment