跳至內容

301 redirect in lightsail

0

How do i create a 301 redirect from a www url to a non-www url in (non-bitnami) lightsail?

已提問 2 個月前檢視次數 59 次
3 個答案
1

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.

專家
已回答 2 個月前
專家
已審閱 2 個月前
  • My site uses HTTPS - do I need to change anything in the htaccess rewrite code above for it to work with SSL

1

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

專家
已回答 2 個月前
專家
已審閱 2 個月前
0

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.

已回答 2 個月前
專家
已審閱 2 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。