2012-07-25 145 views
0

我已經建立了一個靜態域別名來提供沒有cookie的靜態內容,但是,因爲這只是主域的別名,我擔心如果它被無意中鏈接,那麼它可能會被編入索引。我想通過主站點.htaccess文件中的條件方式防止靜態域別名服務除CSS,JS,JPG,GIF文件等之外的任何內容。如何防止靜態域提供非靜態內容?

即是這樣的:

如果域名包括術語「靜態」,然後重定向文件的所有請求「而不是」用的.css,.js文件等,以父域結束。

任何想法?

回答

0

在靜態域的文檔根,將其添加到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]