- 新しい順
- 投票が多い順
- コメントが多い順
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:
-
First, check the virtual host configuration file at
/opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf(if you're running WordPress). -
In this file, look for the
<Directory>section that contains the WordPress configuration. This is where you should add your rewrite rules. -
Make sure the
AllowOverridedirective is set toAllif 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. -
Add your redirect rule within the appropriate
<Directory>section:
RewriteEngine On
RewriteRule ^testimonials\.html$ / [R=301,L]
- 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
