问题原文
原帖链接 · 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:
- Visit Cloudflare
- Create an account and verify your email address
- 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.
- 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
Arecord for the domain apex (@) - I also have a wildcard subdomain proxied
Arecord (*) so that all subdomains (includingwww) get redirected.
- Go to your DNS registrar and update your nameserver (NS) records to be the values that Cloudflare gives you.
- 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.
- 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 ofexample.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/$2where you use your main domain in place ofexample.org. The$2is 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 usehttps://$1example.org/$2to preserve the captured subdomain as well. - Save the page rule.
- URL matches:
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.comwhere you use your alternate domain in place ofexample.com. Look for the cloudflare NS records. - See what server Cloudflare is using for your site:
dig @xx.ns.cloudflare.com example.comwhere you use one of the actual NS records that Cloudflare gave you instead ofxxand again your alternate domain. Look for anArecord 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/whereX.X.X.Xis one of the IP addresses from the previous step and you use your alternate domain in place ofexample.com. Look for aLocation:header with the redirect destination. You can repeat this step with other URLs such ashttp://www.example.com/,http://foo.example.com/,http://example.com/pathandhttps://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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
