301 redirect from http to https and https://www to https://

:warning: IMPORTANT, please fill the questions

We assume you are using Bitnami to deploy your application.

  • Which version of the application are you using?:
    WordPress 5.4.2

  • Please choose how you got the application: Installer (Windows, Linux, macOS), cloud image (AWS, GCE, Azure, …) or VM (VMDK, VBOX):
    Google Cloud - bitnami-wordpress-5-4-1-0-linux-debian-9-x86-64

  • Have you installed any plugin or modified any configuration file?:
    Yes

  • Describe here your question/suggestion/issue (expected and actual results):

  • Steps to reproduce the issue (if relevant):

  • Copy the apache log (if relevant):

Hi
Support key: 27f1cac1-86e5-b711-d80b-def9c2a1826e
I'm trying to add couple of codes for 301 redirect from http://, http://www, https://www to the main url https://

My steps:

sudo nano /opt/bitnami/apps/wordpress/conf/htaccess.conf

<Directory "/opt/bitnami/apps/wordpress/htdocs">
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.animalworld.club$ [NC]
RewriteRule ^(.*)$ http://animalworld.club/$1 [R=301,L]
</Directory>

# BEGIN rlrssslReallySimpleSSL rsssl_version[3.3.4]
<Directory "/opt/bitnami/apps/wordpress/htdocs/">
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
</Directory>
# END rlrssslReallySimpleSSL

I reviewed the documentation at https://docs.bitnami.com/aws/apps/ghost/administration/use-htaccess/ 
But when I check my website, then url categories and articles pages - 404 Not found. Could you please let me know, maybe I do something wrong?

I figured out with the 404 pages, just deactivate, and then activate all of the plugins but still after I added the code 301 redirect to htaccess file, redirect still not working. Please help me. Thanks.

Hi @museland,

In your Apache error log the following message is showing:

[Thu Jun 25 13:52:30.147767 2020] [proxy_fcgi:error] [pid 15246:tid 139740728559360] [client 172.69.34.36:36904] AH01071: Got error 'PHP message: <b>Detecting configuration</b>PHP message: <br><b>SSL Configuration</b>PHP message: testing htaccess rules...PHP message: test page url, enter in browser to check manually: https://animalworld.club/wp-content/plugins/really-simple-ssl/testssl/cloudflare/ssl-test-page.htmlPHP message: htaccess rules tested successfully.PHP message: checking if .htaccess can or should be edited...PHP message: .htaccess does not contain default Really Simple SSL redirectPHP message: .htaccess not writable.PHP message: converting siteurl and homeurl to httpsPHP message: Mixed content fixer successfully detected', referer: https://animalworld.club/wp-admin/options-general.php?page=rlrsssl_really_simple_ssl

Some plugins, like Really Simple SSL, create an .htaccess file in either the /opt/bitnami/apps/APPNAME/htdocs/ or in the /opt/bitnami/apps/APPNAME/htdocs//plugins directory that can not be read by Apache. You need to move the rules from those .htaccess files to /opt/bitnami/apps/APPNAME/conf/htaccess.conf. You can find more information about it in the following guide:
https://docs.bitnami.com/google/apps/wordpress/administration/use-htaccess/#add-a-new-section-in-the-htaccess-file-when-installing-a-plugin-124

Could you tell us why only this line?

RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'

and why not these lines?

RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"' [OR]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ - [env=proto:http]
RewriteCond %{HTTP:CF-Visitor} '"scheme":"https"' [OR]
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ - [env=proto:https]

Regards,
Ibone

Hi @Ibone

Thank you for your reply. Can you please send me step by step how I can move the rules from those .htaccess files to /opt/bitnami/apps/APPNAME/conf/htaccess.conf
Also, should I add just one Really Simple SSL code for 301 redirections, or I need another one for redirection from http://, http://www, https://www to the main URL https://

Hi @museland,

You already have the file /opt/bitnami/apps/wordpress/conf/htaccess.conf (APPNAME=wordpress)
Could you follow the next video? this video shows step by step the process.
https://www.youtube.com/watch?time_continue=189&v=fXNwGl42WbI&feature=emb_logo

Regards,
Ibone

Thanks for your message, also could you please send me the correct code for 301 redirect from www to non www ?

Hi @Ibone
Thanks for your message, also could you please send me the correct code for 301 redirect from www to non www ?

Hi @museland,

To do that you need to add the next lines to the file //opt/bitnami/apache2/conf/bitnami/bitnami.conf add, before the RewriteEngine On the following lines:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.animalworld.club$
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^/?(.*)" "%{REQUEST_SCHEME}://animalworld.in/$1  [R=permanent,L]

You can check with the documentation https://docs.bitnami.com/aws/apps/wordpress/administration/use-single-domain/#redirect-all-domains-to-your-own-domain-123

I hope that helps you.

Hi @Ibone
Thank you very much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.