Ir para o conteúdo

301 redirects in Lightsail

0

I normally use .htaccess to put my 301 redirects of an old page to a new page but since switching to AWS Lightsail, this no longer works. I tried updating /opt/bitnami/apache2/conf/bitnami/bitnami.conf file with: Redirect 301 /testimonials.html / That didnt work - even after restarting apache (even tried to reboot the instance) I also tried: RewriteRule ^/testimonials.html$ / [R=301,L] but that too didnt work

I don't want to allow the htaccess file (as I have read it is not secure) so how can I handle this simple process? Thank in advance

feita há 4 meses70 visualizações
1 Resposta
0

To implement 301 redirects in your AWS Lightsail instance without using .htaccess files, you should modify the Apache configuration files properly. Since you're using a Bitnami-based Lightsail instance, the correct approach is to work with the virtual host configuration files.

The reason your attempts didn't work might be related to the location of the configuration changes or how they were implemented. Here's how to properly set up 301 redirects in your Lightsail instance:

  1. First, check the virtual host configuration file at /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf (if you're running WordPress).

  2. In this file, look for the <Directory> section that contains the WordPress configuration. This is where you should add your rewrite rules.

  3. Make sure the AllowOverride directive is set to All if you want to use .htaccess files. However, since you mentioned you prefer not to use .htaccess for security reasons, you can add your redirect rules directly in this configuration file.

  4. Add your redirect rule within the appropriate <Directory> section:

RewriteEngine On
RewriteRule ^testimonials\.html$ / [R=301,L]
  1. After making changes, restart Apache using:
sudo /opt/bitnami/ctlscript.sh restart apache

If you're still having issues, check that:

  • The RewriteEngine is enabled
  • Your rule pattern matches the URL correctly (note that within the configuration file, you might not need the leading slash)
  • There are no conflicting rules elsewhere in your configuration

This approach allows you to implement 301 redirects securely without relying on .htaccess files.
Sources
Lightsail WordPress Instance - Incorrect HTTP to HTTPS Redirect (302 instead of 301) | AWS re:Post
Community | Securing Wordpress on Lightsail: Hardening Wordpress

respondido há 4 meses
ESPECIALISTA
avaliado há 4 meses

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.