【问题标题】:internaly linking to home page (/index) using ajax when htacess redirects home page to mydomain.com当 htaccess 将主页重定向到 mydomain.com 时,使用 ajax 内部链接到主页 (/index)
【发布时间】:2012-10-30 21:40:25
【问题描述】:

我在我的 Apache .htaccess 文件中使用重定向将所有流量从 index.html 发送到 mydomain.com。为此,我使用以下内容:

Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.mydomain.com/$1 [R=301,L]

我现在遇到的问题是在使用 AJAX 将内容调用到 <div> 时使用到我主页的相对路径。

如果我想从 /index.html 获取内容,我会收到 404 错误。我可以通过使用绝对路径来解决这个问题,即。 “http://mydomain.com”,但是有没有办法我仍然可以使用主页的相对路径?

【问题讨论】:

    标签: javascript ajax .htaccess http-status-code-301


    【解决方案1】:

    就在我的脑海中,我想说您的 URL 参数/锚点没有经过重写。您可以使用 QueryStringAppend QSA 标志来解决这个问题,如下所示:

    RewriteRule ^(.*)index.html$ http://www.mydomain.com/$1 [QSA,R=301,L]
    

    【讨论】:

      猜你喜欢
      • 2021-05-02
      • 2014-10-06
      • 1970-01-01
      • 1970-01-01
      • 2011-05-24
      • 1970-01-01
      • 2016-10-18
      • 2023-04-08
      • 2022-06-30
      相关资源
      最近更新 更多