I want to redirect my website EC2 IP address to the domain name

Keywords: WordPress - AWS - Technical issue - Domain Name (DNS)

bnsupport ID: 15ee5a92-3771-2e46-8115-217ec5ef7dc2

bndiagnostic output:

? Apache: Found possible issues
? Resources: Found possible issues
? Php: Found possible issues
https://docs.bitnami.com/general/apps/wordpress/administration/use-pagespeed/#disable-pagespeed
https://docs.bitnami.com/general/apps/wordpress/troubleshooting/debug-errors-apache/
https://docs.bitnami.com/bch/apps/moodle/troubleshooting/deny-connections-bots-apache/
https://docs.bitnami.com/general/apps/wordpress/configuration/configure-phpfpm-processes/

bndiagnostic failure reason: The documentation did not make any significant change

Description:
Hello, Bitnami Team!

I am facing the biggest trouble with my website. My website IP address and domain name are indexed simultaneously, and thus, it is getting canonicalization and duplicate content problem. How can I set the redirection from my website IP to the domain?
I also followed bitnami guidelines by given link below -

https://docs.bitnami.com/aws/apps/wordpress/administration/use-single-domain/

but still, it is not working. Please help

Thanks in advance!

Hi @sup.vastav

Thanks for using Bitnami WordPress!

Unfortunately, I can’t see any related changes to this in your current configuration files. Let’s try to adapt the changes to your config files:

/opt/bitnami/apache2/conf/bitnami/bitnami.conf

...
<VirtualHost _default_:80>
  DocumentRoot "/opt/bitnami/apache2/htdocs"
  # BEGIN: Support domain renewal when using mod_proxy without Location
  <IfModule mod_proxy.c>
    ProxyPass /.well-known !
  </IfModule>
  # END: Support domain renewal when using mod_proxy without Location
  # BEGIN: Enable HTTP to HTTPS redirection
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
- RewriteCond %{HTTP_HOST} !^localhost
- RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
+ RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
+ RewriteCond %{HTTP_HOST} !^YOUR_DOMAIN.com$
  RewriteCond %{REQUEST_URI} !^/\.well-known
  RewriteRule ^/(.*) https://YOUR_DOMAIN.com/$1 [R,L]
  # END: Enable HTTP to HTTPS redirection
  # BEGIN: Enable non-www to www redirection
  RewriteCond %{HTTP_HOST} !^www\. [NC]
- RewriteCond %{HTTP_HOST} !^localhost
- RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
+ RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
+ RewriteCond %{HTTP_HOST} !^YOUR_DOMAIN.com$
  RewriteCond %{REQUEST_URI} !^/\.well-known
- RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=permanent,L]
+ RewriteRule ^(.*)$ http://www.YOUR_DOMAIN.com%{REQUEST_URI} [R=permanent,L]
  # END: Enable non-www to www redirection
...
<VirtualHost _default_:443>
  DocumentRoot "/opt/bitnami/apache2/htdocs"
  SSLEngine on
SSLCertificateFile "/opt/bitnami/apache2/conf/cademyk.com.crt"
SSLCertificateKeyFile "/opt/bitnami/apache2/conf/cademyk.com.key"

  # BEGIN: Support domain renewal when using mod_proxy without Location
  <IfModule mod_proxy.c>
    ProxyPass /.well-known !
  </IfModule>
  # END: Support domain renewal when using mod_proxy without Location
  # BEGIN: Enable non-www to www redirection
  RewriteEngine On
  RewriteCond %{HTTP_HOST} !^www\. [NC]
- RewriteCond %{HTTP_HOST} !^localhost
- RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
+ RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
+ RewriteCond %{HTTP_HOST} !^YOUR_DOMAIN.com$
  RewriteCond %{REQUEST_URI} !^/\.well-known
- RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=permanent,L]
+ RewriteRule ^(.*)$ https://www.YOUR_DOMAIN.com%{REQUEST_URI} [R=permanent,L]
  # END: Enable non-www to www redirection

Please, note that you will have to change YOUR_DOMAIN.com by your actual domain!

After the changes, please restart the Apache service and see if it works now:

sudo /opt/bitnami/ctlscript.sh restart apache

Best regards,
Jose Antonio Carmona


Was my answer helpful? Click on :heart:

Hi, Thanks for your reply…this code is already added to the config file…but still is not working

Hi, i have replaced config file code by your given code. but when i am trying to restart apache, then i am getting this error…

also IP is not redirecting on domain…please help

Thanks in advance

Hi!

It seems there is a syntax error in your configuration file. Could you please share it so that I can take a look?

$ sudo cat /opt/bitnami/apache2/conf/bitnami/bitnami.conf

Best regards,
Jose Antonio Carmona


Was my answer helpful? Click on :heart:

Correction -

This was the code firstly -

    # Default Virtual Host configuration.

<IfVersion < 2.3 >
  NameVirtualHost *:80
  NameVirtualHost *:443
</IfVersion>

<VirtualHost _default_:80>
  DocumentRoot "/opt/bitnami/apache2/htdocs"
  # BEGIN: Support domain renewal when using mod_proxy without Location
  <IfModule mod_proxy.c>
    ProxyPass /.well-known !
  </IfModule>
  # END: Support domain renewal when using mod_proxy without Location
  # BEGIN: Enable HTTP to HTTPS redirection
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} !^localhost
  RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
  RewriteCond %{REQUEST_URI} !^/\.well-known
  RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
  # END: Enable HTTP to HTTPS redirection
  # BEGIN: Enable non-www to www redirection
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteCond %{HTTP_HOST} !^localhost
  RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
  RewriteCond %{REQUEST_URI} !^/\.well-known
  RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=permanent,L]
  # END: Enable non-www to www redirection
  <Directory "/opt/bitnami/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    <IfVersion < 2.3 >
      Order allow,deny                          
      Allow from all
    </IfVersion>
    <IfVersion >= 2.3 >
      Require all granted
    </IfVersion>
  </Directory>

  # Error Documents
  ErrorDocument 503 /503.html

  # Bitnami applications installed with a prefix URL (default)
  Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"
  # BEGIN: Support domain renewal when using mod_proxy within Location
  <Location /.well-known>
    <IfModule mod_proxy.c>
      ProxyPass !
    </IfModule>
  </Location>
  # END: Support domain renewal when using mod_proxy within Location
</VirtualHost>

# Default SSL Virtual Host configuration.

<IfModule !ssl_module>
  LoadModule ssl_module modules/mod_ssl.so
</IfModule>

Listen 443
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !EDH !RC4"
SSLPassPhraseDialog  builtin
SSLSessionCache "shmcb:/opt/bitnami/apache2/logs/ssl_scache(512000)"
SSLSessionCacheTimeout  300

<VirtualHost _default_:443>
  DocumentRoot "/opt/bitnami/apache2/htdocs"
  SSLEngine on
SSLCertificateFile "/opt/bitnami/apache2/conf/cademyk.com.crt"
SSLCertificateKeyFile "/opt/bitnami/apache2/conf/cademyk.com.key"
            
  # BEGIN: Support domain renewal when using mod_proxy without Location
  <IfModule mod_proxy.c>
    ProxyPass /.well-known !
  </IfModule>
  # END: Support domain renewal when using mod_proxy without Location
  # BEGIN: Enable non-www to www redirection
  RewriteEngine On
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteCond %{HTTP_HOST} !^localhost
  RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
  RewriteCond %{REQUEST_URI} !^/\.well-known
  RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=permanent,L]
  # END: Enable non-www to www redirection
  <Directory "/opt/bitnami/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    <IfVersion < 2.3 >
      Order allow,deny                          
      Allow from all
    </IfVersion>
    <IfVersion >= 2.3 >
      Require all granted
    </IfVersion>
  </Directory>

  # Error Documents
  ErrorDocument 503 /503.html
        
  # Bitnami applications installed with a prefix URL (default)
  Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"
  # BEGIN: Support domain renewal when using mod_proxy within Location
  <Location /.well-known>
    <IfModule mod_proxy.c>
      ProxyPass !
    </IfModule>
  </Location>
  # END: Support domain renewal when using mod_proxy within Location
</VirtualHost>

# Bitnami applications that uses virtual host configuration
Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf"

and I replaced this one, given by you with changing the domain name -

...
<VirtualHost _default_:80>
  DocumentRoot "/opt/bitnami/apache2/htdocs"
  # BEGIN: Support domain renewal when using mod_proxy without Location
  <IfModule mod_proxy.c>
ProxyPass /.well-known !
  </IfModule>
  # END: Support domain renewal when using mod_proxy without Location
  # BEGIN: Enable HTTP to HTTPS redirection
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
- RewriteCond %{HTTP_HOST} !^localhost
- RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
+ RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
+ RewriteCond %{HTTP_HOST} !^cademyk.com$
  RewriteCond %{REQUEST_URI} !^/\.well-known
  RewriteRule ^/(.*) https://cademyk.com/$1 [R,L]
  # END: Enable HTTP to HTTPS redirection
  # BEGIN: Enable non-www to www redirection
  RewriteCond %{HTTP_HOST} !^www\. [NC]
- RewriteCond %{HTTP_HOST} !^localhost
- RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
+ RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
+ RewriteCond %{HTTP_HOST} !^cademyk.com$
  RewriteCond %{REQUEST_URI} !^/\.well-known
- RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=permanent,L]
+ RewriteRule ^(.*)$ http://www.cademyk.com%{REQUEST_URI} [R=permanent,L]
  # END: Enable non-www to www redirection
...
<VirtualHost _default_:443>
  DocumentRoot "/opt/bitnami/apache2/htdocs"
  SSLEngine on
SSLCertificateFile "/opt/bitnami/apache2/conf/cademyk.com.crt"
SSLCertificateKeyFile "/opt/bitnami/apache2/conf/cademyk.com.key"

  # BEGIN: Support domain renewal when using mod_proxy without Location
  <IfModule mod_proxy.c>
ProxyPass /.well-known !
  </IfModule>
  # END: Support domain renewal when using mod_proxy without Location
  # BEGIN: Enable non-www to www redirection
  RewriteEngine On
  RewriteCond %{HTTP_HOST} !^www\. [NC]
- RewriteCond %{HTTP_HOST} !^localhost
- RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
+ RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
+ RewriteCond %{HTTP_HOST} !^cademyk.com$
  RewriteCond %{REQUEST_URI} !^/\.well-known
- RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=permanent,L]
+ RewriteRule ^(.*)$ https://www.cademyk.com%{REQUEST_URI} [R=permanent,L]
  # END: Enable non-www to www redirection

Hi @sup.vastav

Just to make sure, have you included the - and + characters in the modified one? Those characters were just meant to indicate which lines should be removed from your file (-) and which ones should be added (+), so including them will make Apache fail.

If you haven’t please, sharing the output of the following commands will help debugging the issue :slightly_smiling_face:

$ sudo apachectl -t
$ sudo cat /opt/bitnami/apache2/conf/bitnami/bitnami.conf

Best regards,
Jose Antonio Carmona


Was my answer helpful? Click on :heart:

this is the error, i am getting

image

While running second command, i am getting this output
…

    <VirtualHost _default_:80>
      DocumentRoot "/opt/bitnami/apache2/htdocs"
      # BEGIN: Support domain renewal when using mod_proxy without Location
      <IfModule mod_proxy.c>
        ProxyPass /.well-known !
      </IfModule>
      # END: Support domain renewal when using mod_proxy without Location
      # BEGIN: Enable HTTP to HTTPS redirection
      RewriteEngine On
      RewriteCond %{HTTPS} !=on
    - RewriteCond %{HTTP_HOST} !^localhost
    - RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
    + RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
    + RewriteCond %{HTTP_HOST} !^cademyk.com$
      RewriteCond %{REQUEST_URI} !^/\.well-known
      RewriteRule ^/(.*) https://cademyk.com/$1 [R,L]
      # END: Enable HTTP to HTTPS redirection
      # BEGIN: Enable non-www to www redirection
      RewriteCond %{HTTP_HOST} !^www\. [NC]
    - RewriteCond %{HTTP_HOST} !^localhost
    - RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
    + RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
    + RewriteCond %{HTTP_HOST} !^cademyk.com$
      RewriteCond %{REQUEST_URI} !^/\.well-known
    - RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=permanent,L]
    + RewriteRule ^(.*)$ http://www.cademyk.com%{REQUEST_URI} [R=permanent,L]
      # END: Enable non-www to www redirection
    ...
    <VirtualHost _default_:443>
      DocumentRoot "/opt/bitnami/apache2/htdocs"
      SSLEngine on
    SSLCertificateFile "/opt/bitnami/apache2/conf/cademyk.com.crt"
    SSLCertificateKeyFile "/opt/bitnami/apache2/conf/cademyk.com.key"

      # BEGIN: Support domain renewal when using mod_proxy without Location
      <IfModule mod_proxy.c>
        ProxyPass /.well-known !
      </IfModule>
      # END: Support domain renewal when using mod_proxy without Location
      # BEGIN: Enable non-www to www redirection
      RewriteEngine On
      RewriteCond %{HTTP_HOST} !^www\. [NC]
    - RewriteCond %{HTTP_HOST} !^localhost
    - RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
    + RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
    + RewriteCond %{HTTP_HOST} !^cademyk.com$
      RewriteCond %{REQUEST_URI} !^/\.well-known
    - RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=permanent,L]
    + RewriteRule ^(.*)$ https://www.cademyk.com%{REQUEST_URI} [R=permanent,L]
bitnami@ip-172-31-11-43:~$

i added same code, whatever you given to me by replacing the domain name only

Hi…I am still waiting for the solution

Hi @sup.vastav

i added same code, whatever you given to me by replacing the domain name only

My changes were meant to adapt your existing configuration by removing the lines highlighted in red (-) and adding the ones in green (+), replacing the whole file content with them won’t work unfortunately :frowning:

As you have already overwritten the file, try to replace the whole file content this time with the following:

/opt/bitnami/apache2/conf/bitnami/bitnami.conf

# Default Virtual Host configuration.

<IfVersion < 2.3 >
  NameVirtualHost *:80
  NameVirtualHost *:443
</IfVersion>

<VirtualHost _default_:80>
  DocumentRoot "/opt/bitnami/apache2/htdocs"
  # BEGIN: Support domain renewal when using mod_proxy without Location
  <IfModule mod_proxy.c>
    ProxyPass /.well-known !
  </IfModule>
  # END: Support domain renewal when using mod_proxy without Location
  # BEGIN: Enable HTTP to HTTPS redirection
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
  RewriteCond %{HTTP_HOST} !^YOUR_DOMAIN.com$
  RewriteCond %{REQUEST_URI} !^/\.well-known
  RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
  # END: Enable HTTP to HTTPS redirection
  # BEGIN: Enable non-www to www redirection
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
  RewriteCond %{HTTP_HOST} !^YOUR_DOMAIN.com$
  RewriteCond %{REQUEST_URI} !^/\.well-known
  RewriteRule ^(.*)$ http://www.YOUR_DOMAIN.com%{REQUEST_URI} [R=permanent,L]
  # END: Enable non-www to www redirection
  <Directory "/opt/bitnami/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    <IfVersion < 2.3 >
      Order allow,deny
      Allow from all
    </IfVersion>
    <IfVersion >= 2.3 >
      Require all granted
    </IfVersion>
  </Directory>

  # Error Documents
  ErrorDocument 503 /503.html

  # Bitnami applications installed with a prefix URL (default)
  Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"
  # BEGIN: Support domain renewal when using mod_proxy within Location
  <Location /.well-known>
    <IfModule mod_proxy.c>
      ProxyPass !
    </IfModule>
  </Location>
  # END: Support domain renewal when using mod_proxy within Location
</VirtualHost>

# Default SSL Virtual Host configuration.

<IfModule !ssl_module>
  LoadModule ssl_module modules/mod_ssl.so
</IfModule>

Listen 443
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !EDH !RC4"
SSLPassPhraseDialog  builtin
SSLSessionCache "shmcb:/opt/bitnami/apache2/logs/ssl_scache(512000)"
SSLSessionCacheTimeout  300

<VirtualHost _default_:443>
  DocumentRoot "/opt/bitnami/apache2/htdocs"
  SSLEngine on
SSLCertificateFile "/opt/bitnami/apache2/conf/cademyk.com.crt"
SSLCertificateKeyFile "/opt/bitnami/apache2/conf/cademyk.com.key"

  # BEGIN: Support domain renewal when using mod_proxy without Location
  <IfModule mod_proxy.c>
    ProxyPass /.well-known !
  </IfModule>
  # END: Support domain renewal when using mod_proxy without Location
  # BEGIN: Enable non-www to www redirection
  RewriteEngine On
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
  RewriteCond %{HTTP_HOST} !^YOUR_DOMAIN.com$
  RewriteCond %{REQUEST_URI} !^/\.well-known
  RewriteRule ^(.*)$ https://www.YOUR_DOMAIN.com%{REQUEST_URI} [R=permanent,L]
  # END: Enable non-www to www redirection
  <Directory "/opt/bitnami/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    <IfVersion < 2.3 >
      Order allow,deny
      Allow from all
    </IfVersion>
    <IfVersion >= 2.3 >
      Require all granted
    </IfVersion>
  </Directory>

  # Error Documents
  ErrorDocument 503 /503.html

  # Bitnami applications installed with a prefix URL (default)
  Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"
  # BEGIN: Support domain renewal when using mod_proxy within Location
  <Location /.well-known>
    <IfModule mod_proxy.c>
      ProxyPass !
    </IfModule>
  </Location>
  # END: Support domain renewal when using mod_proxy within Location
</VirtualHost>

# Bitnami applications that uses virtual host configuration
Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf"

Note again that you will have to change YOUR_DOMAIN.com by your actual domain! After the changes, please restart the Apache service and see if it works now:

sudo /opt/bitnami/ctlscript.sh restart apache

Best regards,
Jose Antonio Carmona


Was my answer helpful? Click on :heart:

1 Like

Thank you so much for your great support…it is working like a charm

My pleasure :slightly_smiling_face:

Glad to see you were able to solve your issue! We are marking the previous answer as “Solution” and this topic as “Closed”.

If you have any other questions, please do not hesitate to let us know. Feel free to create a new topic referencing this one if necessary.

Best regards,
Jose Antonio Carmona


Was my answer helpful? Click on :heart: