URL 中没有 "www" 的 Facebook OAuth 登录错误

Facebook OAuth Login Error Without "www" in URL

我在 Facebook Oauth 登录中遇到问题。

在我的网站上尝试使用 Facebook (OpenAuth) 登录时,我遇到了这个错误。

我该如何解决这个问题?

Facebook 始终检查 WWW 域。因此,请确保 www.medimart.com.np 在您的浏览器上正常工作。


您必须在此处编辑 hosts 文件:

C:\Windows\System32\drivers\etc

并添加以下行:

127.0.0.1 medimart.com.np
127.0.0.1 www.medimart.com.np

查看如何 Modify your hosts file


A link 分享自 Ermir 的评论。

There are two camps on the subject of the www subdomain. One believe it should be enforced (www.yes-www.org) and the other (no-www.org) that it should be removed. They are both right.

What's important is that there is only a single canonical address to your website – with or without www.

Your server needs to have the URL Rewrite module installed. Chances are that it does already. Azure Websites does and so does all of my other hosting providers.

对没有 WWW 的域 使用以下规则 :

<rule name="Remove WWW" patternSyntax="Wildcard" stopProcessing="true">
  <match url="*" />
  <conditions>
    <add input="{CACHE_URL}" pattern="*://www.*" />
  </conditions>
  <action type="Redirect" url="{C:1}://{C:2}" redirectType="Permanent" />
</rule>

对域 和 WWW:

使用以下规则
<rule name="Enforce WWW" stopProcessing="true">
  <match url=".*" />
  <conditions>
    <add input="{CACHE_URL}" pattern="^(.+)://(?!www)(.*)" />
  </conditions>
  <action type="Redirect" url="{C:1}://www.{C:2}" redirectType="Permanent" />
</rule>

现在您可以在 web.config 文件中添加以上规则:

<system.webServer>
  <rewrite>
    <rules>
      <!-- Add your rules here -->
    </rules>
  </rewrite>
</system.webServer>

正如@AsifAli72090 所说,这是我学到的。

"Facebook always check for the WWW domain."

因此,在尝试使用您的 Facebook 帐户登录时,您的域中必须有 "www"。将 "yourdomain.com" 重定向到 "www.yourdomain.com"。所以我最终在我的 web.config 文件

中添加了这段代码
<system.webServer>
<rewrite>
  <rules>
    <rule name="Redirect domain.com to www" patternSyntax="ECMAScript" stopProcessing="true">
        <match url=".*" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^yourdomain.com$" />
        </conditions>
        <action type="Redirect" url="http://www.yourdomain.com/{R:0}" />
    </rule>
</rules>
</rewrite>
</system.webServer>