You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将HTTPS非WWW域名重定向至HTTPS WWW域名?

Hey Rachel, totally get needing to redirect your root domain to the www version—this is such a common task, and I’ve got you covered with the most reliable methods depending on your server setup. Let’s dive in:

1. Apache Server (Using .htaccess)

If your site runs on Apache, this is the go-to method. Head to your website’s root directory, create or edit the .htaccess file, and add this code:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
  • R=301 sets a permanent redirect, which is best for SEO since it tells search engines to update their indexes to the www version.
  • NC makes the rule case-insensitive (so it works for Example.com too).
  • L tells Apache this is the last rule to process once matched.
2. Nginx Server

For Nginx, locate your site’s configuration file (usually in /etc/nginx/sites-available/ or /etc/nginx/conf.d/). Update or add these server blocks:

# Redirect root domain to www
server {
    listen 80;
    listen [::]:80;
    server_name example.com;
    return 301 https://www.example.com$request_uri;
}

# Your main www site configuration (make sure SSL is set up here)
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name www.example.com;
    # Add your SSL certificate paths, root directory, and other site config here
}

After making changes, restart Nginx to apply them:

sudo systemctl restart nginx
3. HTML Meta Tag (Fallback Option)

If you can’t modify server config right now, add this to the <head> section of your original site’s HTML as a temporary workaround:

<meta http-equiv="refresh" content="0; URL=https://www.example.com">

⚠️ Note: This is less ideal for SEO than server-level redirects, so switch to one of the first two methods as soon as you can.

Quick Checks to Ensure It Works
  • Make sure www.example.com has a valid SSL certificate (no "not secure" warnings after redirect).
  • Test the redirect by visiting https://example.com—you should land on the www version immediately.
  • Use your browser’s DevTools (Network tab) to confirm the redirect status code is 301.

内容的提问来源于stack exchange,提问作者Rachel Willy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:37:41