Forum Moderators: phranque

Message Too Old, No Replies

.htaccess redirect based on referer

inspect my code, please

         

CtrlAltDimension

1:58 am on Oct 5, 2006 (gmt 0)

10+ Year Member



Hello, I have two domain names: example.com and quux-foo.com; Right now, quux-foo.com is parked and automatically goes to example.com

I was fiddling around with my .htaccess file, because I want quux-foo.com to go to http://www.example.com/quux-foo/19/rise-up/

Here is what I have, after RewriteEngine On

RewriteCond %{HTTP_REFERER} ^http://www\.quux-foo\.com [NC]
RewriteRule \.quux-foo\.com\ http://www.example.com/quux-foo/19/rise-up/ [R]

It's not working, which in naturally why I'm here now. Got any advice?

[edited by: jdMorgan at 2:53 am (utc) on Oct. 5, 2006]
[edit reason] Obscured domains. Please see TOS. [/edit]

tsalmark

3:20 am on Oct 5, 2006 (gmt 0)

10+ Year Member



It's to late so I'm not digging out the books but:
1. you have a COND that assumably is true redirected from domain B.
2. you rewrite domain B to a file/dir in Domain A.

you say you redirected B to A so by the time the browser gets to your server, Domain B is not being requested anymore (A is you told it to request A).

you may be able to set the parked domain to forward to: http://www.example.com/quux-foo/19/rise-up/
directly. If the domains are both pointed to your server you could just make the root of domain B the subdir of A.

jdMorgan

5:09 pm on Oct 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteRule 'sees' only a local URL-path; It cannot 'see' the domain name. Therefore, if you include the domain name in the RewriteRule pattern, it will never match and your rule will never be invoked.

In addition, unless you have only one page (with no images or anything else) on the entire quux-foo domain, you will likely want to 'copy' the URL-path (e.g. page name) requested from quux-foo into the new url on example.com, so that quux-foo.com/abc redirects to example.com/abc, and quux-foo.com/xyz redirects to example.com/xyz. That is accomplished by using 'back-references' in mod_rewrite.


RewriteCond %{HTTP_REFERER} ^http://(www\.)?quux-foo\.com [NC]
RewriteRule (.*) http://www.example.com/quux-foo/19/rise-up/$1 [R=301,L]

The above will work to redirect referrals from quux.foo.com (or from www.quux-foo.com) to the same page on www.example.com, if that's what you want to do.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim