大网数据广告活动
网站运营与故障问答

How to avoid SSL warnings about certificate not for the current site when redirecting alternate domains?

· 52CE 我爱测

I have multiple domains forward issue. Domains with plurals and singular e.g.: example.com, examples.com, example.biz, examples.biz I forwarded all of them to https://examples.com and https://www.examples.com but ran into web bro…

问题原文

原帖链接 · johnsnow · CC BY-SA 3.0

I have multiple domains forward issue. Domains with plurals and singular e.g.:

  • example.com,
  • examples.com,
  • example.biz,
  • examples.biz

I forwarded all of them to https://examples.com and https://www.examples.com but ran into web browser warnings about someone could intercept communications as the SSL cert issued is not for the current website I visited. I have SSL cert for https://examples.com and https://www.examples.com

What is the best solution for this?

社区高分解答

原帖链接 · Stephen Ostermiller · CC BY-SA 4.0

Cloudflare is a free solution for redirecting your alternate domains with HTTPS support. Here are detailed instructions for setting it up:

  1. Visit Cloudflare
  2. Create an account and verify your email address
  3. Use the "add a site" feature to add your alternate domain under their free plan. If you are creating an account, it should ask you to do this as a step of the account creation process.
  4. Set up your DNS at Cloudflare
    • Cloudflare will import your DNS from your current web host
    • Keep all TXT, SOA, and MX records as well as any subdomains that you don't want cloudflare to redirect.
    • Ensure that records you do want cloudflare to redirect are "Proxied". Click on the icon in the "Proxy status" column to change whether or not they are proxied. Proxied records will be handled by Cloudflare's web servers.
    • Since we will later add a redirect rule, the IP address you enter for proxied A records doesn't actually matter, no traffic will ever go to it.
    • Make sure you have a proxed A record for the domain apex (@)
    • I also have a wildcard subdomain proxied A record (*) so that all subdomains (including www) get redirected.
  5. Go to your DNS registrar and update your nameserver (NS) records to be the values that Cloudflare gives you.
  6. Cloudflare will try to verify these for you. Don't worry if that doesn't work right away, the verification could take a few hours and Cloudflare will retry it for you.
  7. Go to "Page Rules" and add the following rule to do the redirect.
    • URL matches: *example.com/* Where you use your alternate domain in place of example.com. The first * is a wildcard that matches any subdomain. The second * is a wildcard that matches any path. This single rule should match every request to the domain and its wildcard subdomains.
    • Pick a setting: Forwarding URL
    • Select status code: 301 - Permanent Redirect
    • Enter destination URL: https://example.org/$2 where you use your main domain in place of example.org. The $2 is the URL path captured from the second glob of the URL match. Without $2, all the requests for deep pages would redirect to the home page. This rule strips the subdomains. If desired you could use https://$1example.org/$2 to preserve the captured subdomain as well.
    • Save the page rule.

It could take hours for everything to start working.

  • Your new NS records need to propagate through DNS. This should take a couple hours, but worst case could take a few days.
  • Cloudflare need to update their servers with your rules. This should take a few minutes.
  • Cloudflare needs to create a SSL certificate for your HTTPS requests. This should take a couple hours.

If you are impatient to test things, you can start testing on the command line.

  • See if your NS records have updated: dig NS example.com where you use your alternate domain in place of example.com. Look for the cloudflare NS records.
  • See what server Cloudflare is using for your site: dig @xx.ns.cloudflare.com example.com where you use one of the actual NS records that Cloudflare gave you instead of xx and again your alternate domain. Look for an A record with an IP address that you can use see if the redirects are working on Cloudflare's servers.
  • See if Cloudflare is serving redirects: curl --resolve example.com:80:X.X.X.X --head http://example.com/ where X.X.X.X is one of the IP addresses from the previous step and you use your alternate domain in place of example.com. Look for a Location: header with the redirect destination. You can repeat this step with other URLs such as http://www.example.com/, http://foo.example.com/, http://example.com/path and https://example.com/. Keep in mind it may take a couple hours for the HTTPS redirects to start working.

Cloudflare lets you add many additional alternate domains to your Cloudflare account and set them up the same way. Each of your alternate domains can use its own free plan.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2018-03-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。