2

我工作的一家公司有一个基于 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 重定向并保留我之前的页面排名?

4

3 回答 3

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 文件中写入的确切内容,那就太好了。

于 2014-11-12T09:55:23.860 回答
0

我也有同样的情况。我找到的唯一解决方案是使用以下内容创建 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];
    }
}

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

于 2015-05-13T19:22:44.660 回答
0

由于 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]);
}
于 2015-09-04T19:21:37.963 回答