Welcome to WebmasterWorld Guest from 3.93.74.227

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Redirection

     
9:08 am on Dec 13, 2003 (gmt 0)

New User

10+ Year Member

joined:July 20, 2003
posts:11
votes: 0


Some time ago JD Morgan sorted out a redirection problem for me with the following:

# Block foreign referrers
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://www\.yoursite/ [NC]
RewriteRule .* - [F]

This works perfectly but there is one drawback, it also re-directs sites which are linking to my index page. Is it possible to allow linking to my main index page only, and re-direct all attempts to link to pages within my site to my custom error page?

Thanks in advance.

dcrombie

12:42 pm on Dec 13, 2003 (gmt 0)

Inactive Member
Account Expired

 
 


I think you need to have a [F]inal RewriteRule for "index.html" before the catch-all for .*. I'm sure someone can supply the right syntax.
9:18 pm on Dec 13, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Depends on what your index page is called, but if you just use "domain.com/" as the link to your index page, and don't call it specifically by "domain.com/index.htm" or "domain.com/index.php", then the following should work:

# Block foreign referrers
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://www\.yoursite/ [NC]
RewriteRule . - [F]

The only change that matters is dropping the "*" from the rewriterule pattern. This is for htaccess use. For use in httpd.conf, you'd change the rule to something like:

RewriteRule [^/]+ - [F]

The point in both cases being to require a non-blank filename.

Jim

10:52 pm on Dec 13, 2003 (gmt 0)

New User

10+ Year Member

joined:July 20, 2003
posts:11
votes: 0


Hi Jim

I tried the changes you suggested. When I checked a couple of sites which link to my main page I got error message "you do not have permission to enter mysite.com/index.html

The sites are linking to mysite.com and not specifically to the index page.

Any further suggestions would be appreciated.

11:03 pm on Dec 13, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Brutus,

> if you just use "domain.com/" as the link to your index page, and don't call it specifically by "domain.com/index.htm" or "domain.com/index.php", then the following should work.

That's the problem. So you'll have to add a RewriteCond:


# Block foreign referrers
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index\.html$
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://www\.yoursite/ [NC]
RewriteRule . - [F]

I strongly recommend linking to your home page only as domain.com/ and not as domain.com/index.html. It leaves you with far more easy options later: You can easily change your home page from index.html to index.shtml, or index.php or index.asp for example. But it is a real hassle if every one of your backlinks needs to be updated or handled with a 301 redirect. Anyway, this thread illustrates one of those problems. The fix above should work for you, again assuming we are talking about .htaccess here.

Jim