Forum Moderators: phranque

Message Too Old, No Replies

redirect only .html pages from one domain to another

redirect only .html

         

renton84uk

11:55 pm on Nov 19, 2010 (gmt 0)

10+ Year Member



Hi.

I have a site which loads images and scripts from a second domain.

The second domain is simply pointing to the same location as the first domain. So you could see the same site at both domains.

So I want to block users and bots from seeing the duplicate site. I attempted the follow htaccess code, but I really don't full understand how it works.

RewriteCond %{HTTP_HOST} ^images.domain2.com
RewriteRule (.*)$ [domain1.com...] [R=301,L]

The issue is that this redirects everything, the images and script files being loaded for each page are being redirect back to the main domain.

I would like to be able to just redirect pages ending in html at domain2 to domain one, put keep all other files like scripts and images accessible.

Does any clever htaccess user know how this can be done? or have a better idea of a solution for this?

Thanks very much for your time and help.
Renton

renton84uk

11:44 am on Nov 20, 2010 (gmt 0)

10+ Year Member



I think i should use \.(html|php)$ somehow,

I want to say if it starts with www.domain2.com and ends with \.(html|php)$ then redirect to the equivalent pages at domain1.com

I just cant work out how. Please can someone help :)

thanks very much

renton84uk

9:55 pm on Nov 22, 2010 (gmt 0)

10+ Year Member



does anyone have any pointers? thanks

jdMorgan

9:32 pm on Nov 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The following may help you get started:

# if requested hostname is domain2.com or www.domain2.com and URL-path with
# .html or .php, then redirect to the equivalent resource at www.domain1.com
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com
RewriteRule ^(.+\.(html|php))$ http://www.domain1.com/$1 [R=301,L]

Jim