• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

redirect anything else as images files for subdomain?

Hi experts,

I would like to create a redirect rule for my htaccess which redirects a subdomain from for example images.domainname.com to www.domainame.com if the files which is called is anything else as an image (jpg/png/gif)

The same for a subdomain scripts (css,js)

The backgorund is that I use a cdn server with several subdomains but google start indexing my subdomains now via the cdn servers. I want to prevent google from scanning at all the subdomains since they contain only images and scripts.

thanks for your help
1 Solution
Blocking Google from finding your images/scripts will likely do more harm than good.
If there are parts of your site that you do not want search robots to access then you should do it with robots.txt, not .htaccess.

all you need is:

User-agent: *
Disallow: /images/
Disallow: /js/
Disallow: /css/

Oliver2000Author Commented:
I guess both of you did not understand/read my question well.

@GaryC123: I don't want to block google from my images/scripts, I want to prevent double indexing for separate subdomains. Of course the main domain is normal indexed including all images and scripts. With other words I want that www.domain.com is indexed but not sub.domain.com

@COBOLdinosour: You cant define in robot.txt the subdomains and there for cant separate anything. if I disallow global in my robot.txt images, scripts etc. would not help because I want only prevent SUBDOMAINS from being indexed.

Since there isn't any real folder for the subdomain like I cant place a different robots.txt inside the subdomain either. The subdomains are only CNAME host entries for our cdn server.
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Oliver2000Author Commented:
Found my own solution

I just created a rule

RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteCond %{HTTP_HOST} !^lojas\.domain\.com$
RewriteRule ^robots\.txt$ /robots_disabled.txt [L]

which leaves google scanning the www.domain.com but serve a modified robot.txt if any other subdomain is called. in the robots_disabled.txt file I disallow google.

thankx anyway
Tony McCreathTechnical SEO ConsultantCommented:
Wouldn't redirecting from the cdn urls defeat the point of having a cdn?
Oliver2000Author Commented:
@Tiggerito: Where did I say that the CDN redirect to anything? The subdomains are simple redirects to the cdn servers. the cdn either call the file from original www or have the file cached already. there is no redirecting for the cdns of course. this was not about the cdn or redirection but only to prevent google from scanning the new subdomains created for the cdns.

the point is that google found the subdomans and started to scan my content via this subdomains but the only reason this subdomains exist is for me to use sub.domain.com instead of 234234423server.cdn.com.

anyway solved with the above solution. now google and other search engines get served a different robots.txt on subdomains as for www and lojas.
Tony McCreathTechnical SEO ConsultantCommented:
No worries, I just picked up on "I use a cdn server with several subdomains" and then you are redirecting from those subdomains.
Oliver2000Author Commented:
Solved it!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now