【问题标题】:htaccess allow just a specific url for a specific subdomain and disallow all the resthtaccess 只允许特定子域的特定 url 并禁止所有其余的
【发布时间】:2014-03-10 13:20:51
【问题描述】:

我们的网站有 2 个子域。

  • subdomain1.xxxxx.com
  • subdomain2.xxxxx.com

(我们几天前刚刚创建了第二个)

我想用 .htaccess 完成什么:

所有subdomain2.xxxxx.com/??? 网址不得被搜索引擎看到。 事实上,我们发现 Google 开始索引所有包含两个子域的 url,我们不希望这样。

我们希望将第二个子域仅用于特定的 url,例如:

subdomain2.xxxxx.com/live/

所有其他 url 不得与第二个子域一起使用。 所以谷歌必须只用第二个子域索引这个 url:

subdomain2.xxxxx.com/live/

没有别的... 虽然所有其他 url(例如:subdomain1.xxxxx.com/video/subdomain1.xxxxx.com/photo/ 和所有其他)必须在 subdomain1 中仍然可见和索引。 当然,subdomain1.xxxxx.com/live/ 不能正常工作,因为它只适用于 subdomain2。

如何使用 .htaccess 做到这一点?

【问题讨论】:

    标签: .htaccess subdomain content-indexing


    【解决方案1】:

    在名为subdomain2-robots.txt的文档根目录中创建一个新文件:包含以下内容:

    User-agent: *
    Disallow: /
    Allow: /live/
    

    然后在文档根目录下的 .htaccess 中添加此规则:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^subdomain2\. [NC]
    RewriteRule ^robots\.txt$ /subdomain2-robots.txt [L,NC]
    

    【讨论】:

      猜你喜欢
      • 2021-04-04
      • 1970-01-01
      • 2016-11-02
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 2020-06-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多