【问题标题】:Redirecting main domain to subdomain, Godaddy Wordpress hosting将主域重定向到子域,Godaddy Wordpress 托管
【发布时间】:2015-07-31 18:00:01
【问题描述】:

我在“Godaddy Mananged Wordpress”上为我的 wordpress 网站使用子域 sub.xyz.com(主域)我最近还添加了主域,但保留子域主域以防有人尝试访问 xyz.com 他们不要收到未找到网站的错误。

我对 .htaccess 不熟悉,但我在 stackoverflow 上发现了一条用于重定向的规则。这是我放在我的 .htaccess 文件中的代码,但是我想知道从 SEO 的角度来看这段代码是否合适,并且我不会在搜索引擎上遇到任何问题。

RewriteCond %{HTTP_HOST} ^xyz.com$
RewriteRule ^(.*)$ http://sub.xyz.com/$1 [R=301,L]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    我在保持与 WordPress 的连接完好无损时遇到了问题。似乎谷歌的爬虫仍然能够找到这些页面,并且 SEO 信用也没有转移。这就是我删除的原因:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    

    然后我只需将 .htaccess 更改为:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www.xyz.com$ [NC] 
    RewriteRule ^(.*)$ http://sub.xyz.com/$1 [R=301,L]
    </IfModule>
    

    这会将所有页面重定向到一个页面(www.xyz.com/page 到 sub.xyz.com/page),无论是否带有 www。

    我还删除了 wp-config.php 文件,只是为了更好地衡量。

    只有偏执狂才能生存。 ;)

    【讨论】:

      猜你喜欢
      • 2017-09-03
      • 2017-08-16
      • 2012-07-22
      • 2014-10-05
      • 2017-07-10
      • 2014-01-18
      • 1970-01-01
      • 2021-01-10
      • 2022-01-20
      相关资源
      最近更新 更多