【问题标题】:301 Redirect from Wix to WordPress从 Wix 到 WordPress 的 301 重定向
【发布时间】:2014-03-03 17:32:52
【问题描述】:

我工作的一家公司有一个基于 WIX 的网站。我在 WordPress 上重新创建了站点,移动了主机并重定向了域。然后,我尝试使用标准的 .httaccess 文件 301 重定向将页面重定向到 WordPress 站点上的新 URL。

重定向 301 /#!product/prd1/1063533171/42%22-workstation-(mc-42) http://www.mydomain.com/product/workstation/

我现在发现 WIX 在 url 链接结构中使用了 hashbang (#!)。

如何执行我的 301 重定向并保留我之前的页面排名?

【问题讨论】:

  • 据我所知,您无法从 wix 进行 301 重定向到其他网站,他们有一个帖子,您可以在其中投票支持此功能wix.com/support/forum/html5/editor/other/customize-301-redirect
  • 如果@Francisco Lavin 说的是真的,那么请尝试将 index.php 文件上传到您的 wix 根目录,其中包含一些 PHP 代码以执行 301 重定向。

标签: php wordpress redirect hashbang


【解决方案1】:

我通过将此代码(由 Themee)添加到我的主题目录中的 functions.php 中,设法从 wix 重定向到 wordpress。

function themee_hash_redirects() {
    ?>
    <script type="text/javascript">
        function themee_hashtag_redirect( hashtag, url) {
            var locationHash = document.location.hash;
            if ( locationHash.match(/#!/img) ) {
                if ( hashtag == locationHash ) {
                    document.location.href = url;
                }
            }
        }
        // Examples how to use themee_hashtag_redirect
        themee_hashtag_redirect('#!dvd-content/c1yws', '/dvd-content/');
        themee_hashtag_redirect('#!krav-maga-shirts/c9r5', '/krav-maga-shirts/');
    </script>
<?php
}
add_action('wp_footer', 'themee_hash_redirects');

据我了解,这仅有助于将您的访问者重定向到正确的 URL,但对 SEO 没有帮助。 我认为下一个代码(在 .htaccess 文件中)应该有助于 SEO,但仍然需要一些我不知道的修改。这是来自 Google 论坛的“barryhunter”的帮助。

RewriteCond %{QUERY_STRING} ^_escaped_fragment_=krav-maga-shirts/c9r5
RewriteRule ^$ http://www.972kravmaga.com/krav-maga-shirts [QSA,L]

它是一页重定向的示例。帮助我的人说可以检查它是否在这个页面上工作:http://www.rexswain.com

如果有人能确定 .htacess 文件中究竟应该写什么,那就太好了。

【讨论】:

    【解决方案2】:

    我也有同样的情况。我找到的唯一解决方案是使用以下内容创建 redirect.js 文件:

    var hashesarr = { "#!about-us/c1it7":'/about-us/',
    "#!patio-covers/ce54":'/patio-covers/',
    "#!lattice/c1mz":'/patio-covers/lattice/' };
    
    for (var hash in hashesarr) {
        var patt = new RegExp(hash);
        if (window.location.hash.match(patt) !== null) {
            window.location.href = hashesarr[hash];
        }
    }
    

    然后您应该将此文件上传到您的服务器并将其包含在&lt;head&gt;&lt;/head&gt; 标记之间。这应该可以解决问题。

    【讨论】:

    • 只是一个补充,如果你把这个脚本放在你的 WIX 网站上,那么你需要将你的“for”循环的一部分更改为:window.location.href = 'http://example.com'+hashesarr[hash];
    【解决方案3】:

    由于 wix URL 是主题标签,它们不能通过 .htaccess 重定向。您必须使用 javascript 来重定向 url,例如:

    var redirects = {
        '#!about/c10fk':'about',
        '#!contact/c10fk':'contact',
        '#!help/c10fk':'help'
    };
    
    if(window.location.hash != '' && redirects.hasOwnProperty(window.location.hash)) {
        window.location.replace(redirects[window.location.hash]);
    }
    

    【讨论】:

      猜你喜欢
      • 2012-04-20
      • 2015-06-15
      • 2015-08-03
      • 2016-04-03
      • 1970-01-01
      • 2017-10-06
      • 2013-02-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多