乐闻世界logo
搜索文章和话题

How do I redirect a naked ( apex ) domain to www using Route 53?

1个答案

1

Redirecting a naked domain (e.g., example.com) to a domain with 'www' (e.g., www.example.com) in AWS Route 53 is a common requirement. This is primarily because many websites aim to provide services through a unified URL, enhancing brand recognition and improving SEO. To achieve this functionality, follow these steps:

  1. Configure DNS Records:

    • Create an A Record: First, create an A record (or a CNAME record if using a CDN or other indirect addressing methods) for www.example.com. This record points to the IP address of your web server or a domain resolving to an IP address.
    • Alias Record: Since DNS standards prohibit CNAME records for naked domains, Route 53 provides a special record type called an Alias record. Create an Alias record for the naked domain example.com that directly points to www.example.com.
  2. Configure Redirection (if needed): Although Alias records handle DNS queries, they do not handle HTTP redirection. If you want to redirect users from example.com to www.example.com at the HTTP layer, configure redirection rules on your web server. Below are examples for common web servers:

    • Apache Server: In Apache, add the following rule to the .htaccess file:

      apache
      RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

      This code checks if the requested host is example.com and permanently redirects to www.example.com.

    • Nginx Server: In Nginx, add a server block to the configuration file:

      nginx
      server { server_name example.com; return 301 $scheme://www.example.com$request_uri; }

      This configuration permanently redirects requests for example.com to www.example.com.

This covers the basic steps for redirecting a naked domain to www using AWS Route 53. By properly configuring DNS records and web server redirection rules, you can effectively manage traffic and ensure users access the correct website address.

2024年8月16日 00:23 回复

你的答案