Error Redirect custom domains to the Apache server (from www. to non www.)

Keywords: WordPress - Google Cloud Platform - Technical issue - Services (Apache, MariaDB, MySQL…)

bndiagnostic ID: 8ff8e2ab-75bb-b259-d8be-6daec0c63ccb

bndiagnostic output:

? Apache: Found possible issues
https://docs.bitnami.com/general/apps/wordpress/troubleshooting/debug-errors-apache/

Description:
Hello,

I need to redirect version www.mydomain.com to mydomain.com

I followed this post https://docs.bitnami.com/aws/apps/wordpress/administration/redirect-custom-domains/

I changed /opt/bitnami/apache2/conf/vhosts/wordrpress-vhost.conf file adding:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.(.)$ [NC]
RewriteRule ^(.
)$ http://%1$1 [R=permanent,L]

And changed /opt/bitnami/apache2/conf/vhosts/wordpress-https-vhost.conf file adding:

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1$1 [R=permanent,L]

When I go to www.mydomain.com , it works and redirects to mydomain.com

The problem is when I go to www.mydomain.com/any-other-url , redirections fails because the ulr changes to mydomain.comany-other-url

I can not find the problem. Please, can you help me? Thank you.

Hi @dagalar,

Edit both “RewriteRule” lines and insert one “/” character between %1 and $1.

RewriteRule ^(.*)$ http://%1/$1 [R=permanent,L]
...
RewriteRule ^(.*)$ https://%1/$1 [R=permanent,L]

You will need to restart Apache for the changes to take effect.

Happy to help!


Was my answer helpful? Click on :heart:

Hi @jota,

Thank you, it works!

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