Forum Moderators: phranque

Message Too Old, No Replies

Redirect All Referers except from my own website

Redirecting all referers coming from outside my main website

         

chr0me

4:55 pm on May 15, 2012 (gmt 0)

10+ Year Member



Hi, after searching the forum i could not find anything quite like this rewrite. I have a blog which is hosted in a separate folder from the rest of my website ... then this blog is used in my website using a frame.

So, my main website would be

http://example.com/mymainfolder/News_blog.html

My blog would be integrated in the above page using a iframe... In turn the source of tis iframe would be located at

http://example.com/myblogfolder/

Now the blog page available at the above folder are just bare bones... they only contain the blog without the rest of the main web site elements... no menus, no background pictures etc.

The problem is that when I access the links to my blog from an outside domain.. such as from a google search, or from posts linked in facebook, the links direct to the blog page which is completely out of context from the rest of the website (since the blog is integrated in the main website using a frame).

I would therefore like to redirect all traffic to the blog page which is coming from outside my domain to redirect to the main website (which is integrating the blog in a frame).. thus displaying it in the right and intended context.

I have initially tried to deal with this issue using REFERER rewrite rules such as

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://www.google.com/
RewriteRule /* http://example.com/mainwebsitefolder/Blog_news.html [R,L]
RewriteCond %{HTTP_REFERER} ^http://www.facebook.com/
RewriteRule /* http://example.com/mainwebsitefolder/Blog_news.html [R,L]

Unfortunately, the above rules had no effect whatsoever...

However, since I would like to have ALL external referers redirected, it would be better to have such a rule specified instead of having to list all the external referers one by one.

Would this be possible at all? Any help would be greatly greatly appreciated.

[edited by: incrediBILL at 5:30 pm (utc) on May 15, 2012]
[edit reason] fixed URLS, use Example.com [/edit]

incrediBILL

5:45 pm on May 15, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Didn't test this, just off the top of my head try something like the following:

# If referrer is not your domain
RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)?example\.com
# and referrer is not blank or "-"
RewriteCond %{HTTP_REFERER} !^-?$
# then redirect .html page requests to the blog
RewriteRule \.html http://example.com/mainwebsitefolder/Blog_news.html [R,L]

lucy24

8:43 pm on May 15, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Now the blog page available at the above folder are just bare bones... they only contain the blog without the rest of the main web site elements... no menus, no background pictures etc.

Do you mean that it's supposed to be that way, or that it comes out that way even though it isn't what you want?

chr0me

3:07 pm on May 16, 2012 (gmt 0)

10+ Year Member



Thanks for the suggestion inrediBILL ... Still not working though... it seems as though it had no effect whatsoever. I wonder whats wrong.

lucy24, yes its supposed to be that way... because the blog is created in wordpress and all I'm doing is embedding the wordpress minisite with just the blog into the main blog page.

chr0me

3:55 pm on May 16, 2012 (gmt 0)

10+ Year Member



I was thinking I would need to add something like this

# If referrer is not your domain
RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)?example\.com
# and referrer is not blank or "-"
RewriteCond %{HTTP_REFERER} !^-?$

# and linking to anything in a particular sub-folder
RewriteCond ...

# then redirect .html page requests to the blog
RewriteRule \.html http://example.com/mainwebsitefolder/Blog_news.html [R,L]


To be more specific, I need to redirect everything going to http://example.com/myblogfolder/
and redirect it to
http://example.com/mymainfolder/News_blog.html

dougwilson

4:01 pm on May 16, 2012 (gmt 0)

10+ Year Member Top Contributors Of The Month



I use this

#obselete directory to relevant
RedirectMatch 301 ^/myblogfolder/.*$ http://example.com/mymainfolder/News_blog.html

chr0me

4:39 pm on May 16, 2012 (gmt 0)

10+ Year Member



Neat, however, that would redirect all access from anywhere. I just want to redirect access for those visiting the blog section from outside my website domain... since my own website still needs to be able to call onto the blogfolder and use its contents

lucy24

10:18 pm on May 16, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You want a negative condition, like

RewriteCond %{HTTP_REFERER} !example.com
RewriteRule (/|\.html)$ http:// et cetera

The (/|\.html)$ part (replace html with whatever extension you really use) is to keep the server from having to stop and evaluate the condition on every single request. Images, stylesheets and so on will always give your site as referer-- unless it's a hotlink, which is an entirely different Rewrite.

But you also have to think about the empty-referer problem. This applies to two groups: search engines and some humans. Most of those referer-less humans have no idea what their browser or ISP is doing. So decide whether you want to include an option for ^-?$ ("referer is blank"). Be careful! That one will be a positive condition, while your primary condition is negative.