Forum Moderators: mack

Message Too Old, No Replies

How do I test a redirect?

         

houseofstrauss

3:23 pm on Oct 4, 2003 (gmt 0)

10+ Year Member



I have a redirect on all my pages as below. It is supposed to ignore page calls from my own domain but NOW, does it work, how do I test it? I think it will only redirect if it is called from an independant referer. I tried calling the url for the redirected page and it did not transfer

a/ Can someone tell me if this script is sound?
b/ How can I test it before inputting to pages?

<script language=javascript>
//check if the referrer of the page is not my site
if( document.referrer!= 'http://domain/dir/' )
{
//redirect to my index page
location.replace ('http://domain/dir/index_file.htm');

</script>

Thank-you, Richard

[edited by: houseofstrauss at 4:02 pm (utc) on Oct. 4, 2003]

claus

3:44 pm on Oct 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld houseofstrauss:)

I have a strong feeling that

1) document.referrer is not recognized by all browsers, just some specific Netscape versions as i recall.

2) your URL's will be deleted as they are against the forum TOS ;)

Before your url's got deleted (writing in past tense, as they will be) i got a page saying "this page should redirect" - it didn't. IE6

/claus

houseofstrauss

4:05 pm on Oct 4, 2003 (gmt 0)

10+ Year Member



Thank-you for the welcome. I have ammended my urls. The pages were completly blank except for the test code, sometimes it helps to view source. My appologies If this looked like a promo.

If document referer is not the way to go do you have any other suggestions please. Php is not offered by my host or I would use session redirect. However, I do have cgi access on another server, but I cant call scripts from SSI

Thanks Richard

claus

6:05 pm on Oct 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



oh you could append a "?internal" to your internal links, like this:

www.example.com/page.htm?internal

...and then on that page (page.htm) check for that parameter, using

location.search()

/claus

tedster

6:46 pm on Oct 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



document.referrer is not recognized by all browsers, just some specific Netscape versions as i recall.

According to the O'Reilly JavaScript book, document.referrer was not recognized by IE3 -- that may be what you're remembering, claus.

For today's purposes, document.referrer is a standard and widely supported property. It's just that the content of that property is not very reliable -- but that's a different browser issue than whether javascript support exists for the property.

<added>
O'Reilly actually suggests a script for this purpose -- redirecting everyone to your home page if the referrer is not one of your pages.

if {document.referrer.indexOf("mysite.com") == -1}
window.location = "http://mysite.com/index.html";

However, as you know and they remark, this is not a "serious" measure and will not work in all cases. It will also keep someone from viewing your internal pages if they have javascript turned on but their browser is not sending an accurate referrer for any reason.
</added>

claus

11:48 am on Oct 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> the content of that property is not very reliable

I think i got this totally wrong. At least, right now, i really hope so. On second thoughts i'm actually involved in a project where that property is widely used, i just didn't think about it for some reason.

As i recall it now, there was some issues related to Javascript 2 support, anyway, for that project the problem was solved somehow (it's a couple of years back) - now i have to find out how it was done, and what this means for the outcome of this project as well as another i'm currently working on. I simply need to be able to use this property or identify it another way. Thanks a lot for mentioning this.

/claus

houseofstrauss

1:32 pm on Oct 5, 2003 (gmt 0)

10+ Year Member



if {document.referrer.indexOf("mysite.com") == -1}
window.location = "http://mysite.com/index.html";
Thanks for this snippet Tedster, It does create the divert I wanted although, being javascript it is not water tight. Another isssue that occured to me is how SEs handle pages with this type of direct; my pages are real content pages that are to be viewed in an iframe (that's the reason for redirect)placed in the main index page. I do want them indexed and not filtered out as a cloaking page etc. Do you know of any downside using this redirect?

Richard

RonPK

8:45 am on Oct 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the purpose of the script is to make sure the page is being viewed in a framed context, it's better to check something like:

if (top.frames.length == 0)

or, shorter:

if (top == self).

If true, make javascript build your frameset.

You really should not use document.referrer. It can be filtered by firewalls, and some browsers can be set not to send it. In those cases, using the snippet in msg #5 could cause an endless loop...

houseofstrauss

12:41 pm on Oct 10, 2003 (gmt 0)

10+ Year Member



Thank-you RonPK re your suggestion. In fact the purpose of this script is exactly what you guessed; the pages I want redirected are all to be viewed within iframes on my index page, not by themselves. And Yes, the 'document.referrer' script function DID cause problems with loops. I had considered using .htaccess file, redirecting all .htm files to the index_page (If this was possible?) but now your solution looks more elegant. My current setup simply uses 2 iframes in the index page to target all other pages, so the important requirement is that external referrers redirect to the index page, but from there, all pages are viewable within the iframe. All pages need to be S/E friendly also! I'm not an html/JS wizard, so please can you spell out your suggestions more fully, now you see my setup.

Regards, Richard

RonPK

1:56 pm on Oct 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, two things have to be done:
1. on each page to be framed: check whether it's framed; if not, redirect to the indexpage and tell it what to put in which iframe
2. make the indexpage understand what to put in which iframe ;)

So, on the pages to be framed, put this piece of script in the <head> section:

<script type="text/javascript">
if (top == self) location = "indexpage.html?ifr=if1&ifrloc=" + escape('this_page.html');
</script>

'this_page.html' being the file name of the page, 'if1' the name of the iframe it should be put into.

On indexpage.html:

<iframe src="default_page1.html" name="if1" id="if1" width="200" height="200"></iframe>
<br>
<iframe src="default_page2.html" name="if2" id="if2" width="200" height="200"></iframe>
<script type="text/javascript">
var locs = location.search;
if (locs && locs.length > 0) {
var ifr = locs.substr(5, 3);
var ifrloc = unescape(locs.substr(16));
window.frames[ifr].location = ifrloc;
}
</script>

Make sure the script comes after the iframe-tags.

It may not be the most elegant scripting, but it seems to work in major browsers (javascript enabled, of course).

houseofstrauss

8:01 pm on Oct 12, 2003 (gmt 0)

10+ Year Member



Thank-you for the above piece of code. This looks like a very useful script. Having the pages load in the correct iframe is a bonus!

Many Thanks, Richard

houseofstrauss

12:24 pm on Oct 14, 2003 (gmt 0)

10+ Year Member



As a follow up from my previous question: Now that all pages are directed to my home page, I still need to make them SEO. Every 3 paqe frameset has potential for metatags. The frameset holding page has no content thus potential for 100% density through <title> and <descrition> while the other pages in the set have higher content and keyword density. Can you offer any advice regarding SEO so as not to cause 'spamming ignores' from SEs?

Thanks Richard