- Newest
- Most votes
- Most comments
Hello.
Please change "bitnami.conf" as follows.
"[R,L]", which is set by default when setting an SSL certificate, uses 302 as the HTTP status code.
Therefore, you can set the status code to 301 by setting "[R=301,L]".
# Default Virtual Host configuration.
# Let Apache know we're behind a SSL reverse proxy
SetEnvIf X-Forwarded-Proto https HTTPS=on
<VirtualHost _default_:80>
DocumentRoot "/opt/bitnami/apache/htdocs"
# BEGIN: Configuration for letsencrypt
Include "/opt/bitnami/apps/letsencrypt/conf/httpd-prefix.conf"
# END: Configuration for letsencrypt
# 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=301,L] #edit
# END: Enable HTTP to HTTPS redirection
<Directory "/opt/bitnami/apache/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Error Documents
ErrorDocument 503 /503.html
# 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>
Include "/opt/bitnami/apache/conf/bitnami/bitnami-ssl.conf"
Also, change "/opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf" as follows.
<VirtualHost 127.0.0.1:80 _default_:80>
ServerName www.example.com
ServerAlias *
DocumentRoot /opt/bitnami/wordpress
# BEGIN: Configuration for letsencrypt
Include "/opt/bitnami/apps/letsencrypt/conf/httpd-prefix.conf"
# END: Configuration for letsencrypt
# 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=301,L] #edit
# END: Enable HTTP to HTTPS redirection
<Directory "/opt/bitnami/wordpress">
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride None
Require all granted
# BEGIN WordPress fix for plugins and themes
# Certain WordPress plugins and themes do not properly link to PHP files because of sy
mbolic links
# https://github.com/bitnami/bitnami-docker-wordpress-nginx/issues/43
RewriteEngine On
RewriteRule ^bitnami/wordpress(/.*) $1 [L]
# END WordPress fix for plugins and themes
# BEGIN WordPress
# https://wordpress.org/support/article/htaccess/#basic-wp
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
# BEGIN Disable WordPress XML-RPC endpoint
# Disable the outdated WordPress XML-RPC endpoint to prevent security vulnerabilities.
# https://github.com/bitnami/containers/pull/51077
<Files xmlrpc.php>
Order Allow,Deny
Deny from all
</Files>
# END Disable WordPress XML-RPC endpoint
</Directory>
Include "/opt/bitnami/apache/conf/vhosts/htaccess/wordpress-htaccess.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>
After changing the configuration file, stop and start it using the following commands.
sudo /opt/bitnami/ctlscript.sh stop
sudo /opt/bitnami/ctlscript.sh start
The issue you're experiencing with your Lightsail WordPress instance issuing a 302 (temporary) redirect instead of a 301 (permanent) redirect from HTTP to HTTPS could be related to the Apache configuration on your Bitnami WordPress stack.
Given that you've already checked the common causes and ruled out WordPress plugins and .htaccess files, the problem likely lies in the Apache configuration files.
To resolve this issue, you might need to modify the Apache configuration. Specifically, you should look into editing the file located at /opt/bitnami/apache/conf/vhosts/00_status-vhost.conf. In this file, you can add a rewrite rule to force a 301 redirect from HTTP to HTTPS.
Here's an example of what you could add to that file:
Define CUSTOM_DOMAIN_NAME "yourdomain.com"
RewriteEngine On
<VirtualHost *:80 *:443>
ServerName www.yourdomain.com
RewriteRule ^/(.*) https://${CUSTOM_DOMAIN_NAME}/$1 [R=301,L]
</VirtualHost>
Replace "yourdomain.com" with your actual domain name. This configuration tells Apache to use a 301 (permanent) redirect for all HTTP requests to the HTTPS version of your site.
After making these changes, you'll need to restart the Apache service for the changes to take effect. You can do this by running the appropriate restart command for your Bitnami stack.
If this doesn't resolve the issue, you may need to investigate further into other Apache configuration files or consult with AWS support for more specific guidance related to your Lightsail instance configuration.
Sources
Lightsail Bitnami Wordpress with CloudFront www. Redirect | AWS re:Post
Relevant content
- asked 4 months ago

Bro you are the best. Thanks a lot it works like wonders