未捕获的 DOMException:无法在 'History' 上执行 'pushState':

Uncaught DOMException: Failed to execute 'pushState' on 'History':

我有一个问题,它会根据用户的不同出现在不同的场景中。

A 组:当 select 用户加载到主页并单击应加载 AJAX 的导航锚点并使用 history.pushState('', '' , 目的地网址);他们没有收到任何回复。控制台中显示一条错误消息:

Uncaught DOMException: Failed to execute ‘pushState’ on ‘History’: A history state object with URL ‘http://example.net/foo’ cannot be created in a document with origin ‘http://www.example.net’ and URL ‘http://www.example.net/

根据搜索,我认为问题不在于示例中包含 www。net/foo。我将导航锚点更新为“http://www.example.net/foo”。

这解决了 A 组的问题,但为更大的用户群 B 组带来了同样的问题,并出现类似的错误:

Uncaught DOMException: Failed to execute 'pushState' on 'History': A history state object with URL 'http://www.example.net/foo' cannot be created in a document with origin 'http://example.net' and URL 'http://example.net/'.

对于 B 组,url 差异是相反的。对于两个组来说,该问题似乎都与浏览器无关。该站点使用 Craft CMS。

关于可能发生的事情的任何方向或解决方案,我该如何为这两个群体解决这个问题?

感谢@Patrick Evans。使用 mod_rewrite 的建议让我来到这里:https://httpd.apache.org/docs/2.4/rewrite/remapping.html#canonicalhost

我最终使用了 "if" 指令建议,但也测试了 mod_rewrite,它也有效。

    <If "%{HTTP_HOST} != 'www.example.net'">
      Redirect "/" "http://www.example.net/"
    </If>