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

HTAccess配置致WWW重复重定向,请求技术支持

Fixing the "https://www.www..." Redirect Issue

Hey there, sorry to hear you're stuck with this frustrating double-"www" redirect problem—nothing derails Google Search Console verification faster than a wonky .htaccess rule. Let’s break down what’s likely going wrong and get it sorted quickly.

Common Root Cause

Most of the time, this happens because your HTTPS and WWW enforcement rules are either in the wrong order, or they’re incorrectly concatenating the hostname without checking if "www" is already present. For example:

  • If you first force HTTPS then try to add "www" to the already-HTTPS hostname, you might end up appending "www" to www.yourdomain.com, creating www.www.yourdomain.com.
  • Or your rules might use %{HTTP_HOST} directly without stripping an existing "www" first.

Fix 1: Separate, Ordered Rules (Easy to Read)

This approach first standardizes the hostname to WWW, then forces HTTPS—no duplication possible:

# Enable rewrite engine
RewriteEngine On

# 1. Redirect non-WWW to WWW (only if not already WWW)
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=302,L]

# 2. Redirect HTTP to HTTPS (only if not already HTTPS)
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=302,L]
  • Use R=302 (temporary redirect) while testing—once you confirm it works, switch to R=301 (permanent) for SEO.
  • The [NC] flag makes the host check case-insensitive (so Www. or WWW. are also caught).

Fix 2: Combined Rule (More Concise)

If you prefer a single rule that handles both non-WWW and HTTP in one go, this avoids duplication by capturing the base domain first:

RewriteEngine On

# Redirect both non-WWW and HTTP to HTTPS + WWW
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^(.*)$ https://www.%1/$1 [R=302,L]
  • %1 grabs the part of the hostname after any existing "www.", so we only add "www." once to the base domain.

Critical Testing Tips

  • Clear your browser cache or use incognito mode—301 redirects get cached aggressively, so old rules might still be in effect.
  • Test both http://yourdomain.com and http://www.yourdomain.com—both should land on https://www.yourdomain.com without duplication.
  • Double-check your hosting panel (cPanel, Plesk, etc.)—some hosts have built-in redirect tools that might conflict with your .htaccess rules. Disable those if you’re using custom .htaccess.

For Google Search Console verification, make sure you’ve added the exact target URL (https://www.yourdomain.com) as a property, and that the redirects are resolving correctly before re-trying verification.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:57:47