To Force a WordPress Site Using a https via htaccess

To Force a Wordpress Site Using a https via htaccess

To Force a WordPress Site Using a https via htaccess

3715 2683 fradipta25

To Force a WordPress Site Using a https via htaccess,

add the following lines (dont forget to replace https://yourdomain.com with your domain address).

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]

and add them just after RewriteBase /. here`s an example how it will look:

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://yourdomain.com/$1 [L,R=301,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Forbid WordPress to Modify the Htaccess

So, now every page of your wordpress would redirect to https, but in case you change the permalinks, wordpress will change the content of .htaccess file and revert what you`ve modified. To stop that, add this line of code in your theme’s functions.php file:

add_filter('flush_rewrite_rules_hard','__return_false');

Keep the modified function.php as it is, as you update the theme

When you update the theme, most likely your functions.php would be updated and the change you made would also gone. to prevent that, edit the function.php in your child theme. or use “my custom function” plugin