0

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

即类似的东西:

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

有任何想法吗?

4

1 回答 1

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]
于 2012-08-26T07:01:05.523 回答