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

如何将所有WWW请求重定向至HTTPS非WWW地址?现有方案无效求指导

Fixing Your /about-us Redirect Issue

Hey Sam, let’s get this redirect sorted out—those mixed protocol and www variants of your /about-us page should all land on https://example.com/about-us without a hitch.

The problem with most generic www-to-non-www + HTTPS rules is they often handle the domain/protocol globally but don’t target the specific /about-us path, or they’re ordered incorrectly so other rules interfere. Here’s a targeted, tested solution for your .htaccess file:

RewriteEngine On

# Redirect all 3 target URLs to https://example.com/about-us
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^about-us$ https://example.com/about-us [R=301,L]

Let’s break down what each part does:

  • RewriteEngine On: Turns on Apache’s URL rewriting module—this is mandatory for any rewrite rules to work.
  • First RewriteCond: Matches requests coming to the www.example.com subdomain (covers https://www.example.com/about-us).
  • [OR]: Tells Apache to trigger the rule if either condition is true.
  • Second RewriteCond: Matches requests using HTTP (covers both http://www.example.com/about-us and http://example.com/about-us).
  • RewriteRule: When the request path exactly matches about-us, it redirects to your desired HTTPS, non-www URL. R=301 is a permanent redirect (great for SEO), and L tells Apache to stop processing further rules once this one runs.

Critical Notes to Make This Work:

  • Place this rule first: If you have other rewrite rules in your .htaccess, put this at the top—rules run top-to-bottom, and later rules might override this one.
  • Test with 302 first: Replace R=301 with R=302 temporarily while testing. Browsers cache 301 redirects aggressively, so using a temporary redirect lets you tweak without clearing cache constantly. Switch back to 301 once you confirm it’s working.
  • Ensure mod_rewrite is enabled: Check with your hosting provider or server admin that Apache’s mod_rewrite module is turned on—this is required for .htaccess rewrite rules to function.

Give this a try, and you should see all three source URLs redirect cleanly to your target page.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 03:31:19