- Newest
- Most votes
- Most comments
In addition to the agent's response, here are the specific configuration snippets for the most common web servers to help you implement the 301 redirect:
NGINX
Edit your site configuration file (e.g., /etc/nginx/sites-available/default) and add this block:
server {
listen 80;
server_name www.yourdomain.com;
return 301 $scheme://yourdomain.com$request_uri;
}
Apache
Add these lines to your .htaccess file or your virtual host configuration:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
Note: After saving the changes, remember to restart your service using sudo systemctl restart nginx or sudo systemctl restart apache2. Also, ensure that your DNS settings in Lightsail include an A-record for both the www and non-www versions pointing to your static IP.
To set up a 301 redirect from www.redirect.com to redirected.com in AWS Lightsail, you need to configure Apache .htaccess or virtual host rules:
https://docs.aws.amazon.com/lightsail/
https://repost.aws/questions/QUEQg-iGqMTZqkkzFwiz2kZg/redirection-www-to-non-www-in-aws-lightsail
To create a 301 redirect from a www URL to a non-www URL in Lightsail, you'll need to configure your web server directly. The specific method depends on which web server you're using (such as NGINX or Apache).
For NGINX, you would add a server block in your NGINX configuration file that listens for the www version of your domain and redirects it to the non-www version. This typically involves editing your NGINX configuration file (usually located at /etc/nginx/sites-available/default or /etc/nginx/nginx.conf) and adding a redirect rule using the return 301 directive.
For Apache, you would use the .htaccess file or the Apache configuration file to set up a redirect using mod_rewrite or the Redirect directive.
After making these configuration changes, you'll need to restart your web server for the changes to take effect. You'll also want to ensure that both your www and non-www domains are properly configured in your DNS settings to point to your Lightsail instance's static IP address.
Unfortunately, I don't have specific step-by-step instructions for configuring 301 redirects in Lightsail instances in the information available to me. You may want to consult the official documentation for your specific web server software for detailed configuration syntax.
Relevant content
- asked 10 months ago
- asked 2 years ago
- AWS OFFICIALUpdated a year ago

My site uses HTTPS - do I need to change anything in the htaccess rewrite code above for it to work with SSL