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

HTTPS www域名重定向至非www域名失败,求解决方法

Troubleshooting HTTPS www → Non-www Redirect Issues

Let’s break down why your current .htaccess rule might not be working, and walk through actionable fixes step by step:

1. Verify Apache & .htaccess Core Settings

Before digging into the rule itself, confirm these foundational server configurations—they’re the most common culprits for ignored .htaccess rules:

  • Mod_rewrite is enabled: If you have server access, run a2enmod rewrite and restart Apache. If not, check with your hosting provider to ensure this module is active.
  • .htaccess is in the root directory: Make sure the file lives in the same folder as your site’s main index.html/index.php file, not a subfolder.
  • AllowOverride is set to All: In your Apache virtual host config, the <Directory> block for your site must have AllowOverride All (instead of None or Limit). Without this, Apache ignores all .htaccess rules entirely.

2. Clear Browser Cache (Critical for 301 Redirects)

Permanent 301 redirects are aggressively cached by browsers. If you tested broken rules earlier, your browser might be ignoring the new, correct rule. Test your site in:

  • A private/incognito window
  • Or clear your browser’s full cache (use Ctrl+Shift+Del on most desktop browsers)

3. Simplify the Rule to Isolate Issues

Your combined rule handles both HTTP→HTTPS and www→non-www, but splitting it into distinct steps makes debugging easier. Replace your current code with this:

RewriteEngine On

# First, force all traffic to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]

# Then, redirect www subdomain to non-www (only for HTTPS requests)
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

This separates the logic, so you can test if HTTPS enforcement works first, then confirm the www→non-www redirect.

4. Check for Conflicting Server-Level Rules

Redirects set in your Apache virtual host config, or via hosting control panels (like cPanel/Plesk’s redirect tools), can override .htaccess rules. Double-check:

  • Your virtual host file for any Redirect or RewriteRule directives targeting www/non-www
  • Your hosting control panel’s redirect manager—disable any conflicting rules you find there.

5. Test with Curl to Bypass Browser Cache

Use the curl command in your terminal to see the raw server response (this avoids browser caching entirely):

curl -I https://www.danielleb.com

Look for a Location: header pointing to https://danielleb.com and a 301 Moved Permanently status code. If you don’t see these, the rule isn’t being applied at the server level.

6. Confirm SSL Certificate Coverage

If your SSL certificate only covers danielleb.com (not www.danielleb.com), browsers might block the redirect due to a certificate error. Ensure your certificate includes both the root domain and www subdomain (a wildcard certificate or SAN certificate works for this).


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 09:55:54