【问题标题】:How to prevent a static domain serving non static content?如何防止静态域提供非静态内容?
【发布时间】:2012-07-23 19:39:25
【问题描述】:

我已经设置了一个静态域别名来提供不带 cookie 的静态内容,但是由于这只是主域的别名,我担心如果它被无意链接到,那么它可能会被编入索引。我想通过主站点 .htaccess 文件中的条件来防止静态域别名提供除 CSS、JS、JPG、GIF 文件等以外的任何内容。

即类似:

如果域名包含术语“静态”,则将对以 .css、.js 等结尾的“非”文件的所有请求重定向到父域。

有什么想法吗?

【问题讨论】:

    标签: .htaccess redirect static dns cookieless


    【解决方案1】:

    在静态域的文档根目录中,将其添加到 htaccess 文件中(最好靠近顶部,或任何现有规则的上方):

    RewriteEngine On
    
    # check if hostname includes "static"
    RewriteCond %{HTTP_HOST} static
    
    # and the request isn't for a file ending with one of these extensions
    RewriteCond %{REQUEST_URI} !\.(css|js|jpe?g|gid|png)$ [NC]
    
    # then redirect whatever the request is to the parent domain
    RewriteRule ^(.*)$ http://parent.domain.com/$1 [L,R=301]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-24
      • 2018-02-12
      • 2012-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多