How do I rewrite all requests from a specific domain name to my site with .htaccess?
For example, if http://www.example.com
had a link to my site, then I want to redirect them to a different page on my site, but other links from other websites and direct links should display the requested page like normal.
I've been getting in a muddle with how to do this... Thanks in advance!
UPDATE:
Some information as requested in an answer:
My stripped down .htaccess file looks like this:
# irrelevant all squashed together (issue still remains when used like this)
<Files .htaccess>
order allow,deny
deny from all
</Files>
Options +FollowSymLinks
RewriteEngine On
RewriteOptions MaxRedirects=10
DirectoryIndex index.php
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301]
ErrorDocument 400 /error.html
ErrorDocument 401 /error.html
ErrorDocument 403 /error.html
ErrorDocument 404 /error.html
ErrorDocument 500 /error.html
Options All -Indexes
IndexIgnore *
LimitRequestBody 10240000
#redirect
RewriteCond %{HTTP_REFERER} ^http://(www\.)?badsite\.com/ [NC]
RewriteRule !^error\.html /error.html [L,NC,R=302]
The header of the page I am visiting looks like this:
Referer: http://www.badsite.com/wiki/Page
2nd UPDATE:
The intended actions are:
- Visit
http://www.example.com/wiki/Page
- Click on link to
http://www.mysite.co.uk/thispage/here
- Because of the
example.com
, I should be redirected tohttp://www.mysite.co.uk/badpage
instead ofhttp://www.mysite.co.uk/thispage/here
like all other requests.