문제

I have set up a static domain alias to serve static content without cookies, however as this is just an alias of the main domain I'm concerned that if it gets linked to inadvertently then it might be indexed. I would like to prevent the static domain alias from serving anything but CSS, JS, JPG, GIF files etc by way of a conditional in the main site .htaccess file.

i.e. something like:

If domain name includes the term 'static' then redirect all requests for files 'not' ending with .css, .js etc to the parent domain.

Any ideas?

도움이 되었습니까?

해결책

In the document root of the static domain, add this to the htaccess file (preferably closer to the top, or above any existing rules):

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]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top