Avatar of Oliver2000
Oliver2000Flag for Brazil asked on

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
Apache Web ServerSearch Engine Optimization (SEO)Web Development

Avatar of undefined
Last Comment

8/22/2022 - Mon

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/


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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Tony McCreath

Wouldn't redirecting from the cdn urls defeat the point of having a cdn?

@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 McCreath

No worries, I just picked up on "I use a cdn server with several subdomains" and then you are redirecting from those subdomains.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

Solved it!