Forum Moderators: Robert Charlton & goodroi

Message Too Old, No Replies

301 Redirects - Relative URLs okay?

         

Decius

9:55 pm on Nov 29, 2006 (gmt 0)

10+ Year Member



Will Google heed and transfer information properly via relative 301 redirects?

Thanks.

g1smd

10:04 pm on Nov 29, 2006 (gmt 0)

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



What do you mean by "relative" redirects?

The 301 redirect always returns the full URL in the HTTP header.

Decius

10:08 pm on Nov 29, 2006 (gmt 0)

10+ Year Member



Specifically, in using PHP when you submit the header redirect code:

Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: /blah/blahblah.htm" );

As you can see, it's a RELATIVE redirect, not ABSOLUTE.

What do you mean it returns a full url?

g1smd

10:21 pm on Nov 29, 2006 (gmt 0)

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



Put the code on your page, then test the response with WebBug set to HTTP/1.1 and see what you get.

Decius

10:29 pm on Nov 29, 2006 (gmt 0)

10+ Year Member



Does anyone other than g1smd have any reliable information about this?

Thanks.

Decius

10:41 pm on Nov 29, 2006 (gmt 0)

10+ Year Member



I've read in numerous places that you should use absolute urls, but without any reasoning.

As a result I've changed it so they are all absolute, but I am interested as to why that difference would exist.

MThiessen

11:30 pm on Nov 29, 2006 (gmt 0)

10+ Year Member



absolute is best IMHO use .htacces

301 redirect page.html http://www.example.com/newpage.html

theBear

11:35 pm on Nov 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you seen site crossfire?

That is where www.example.com/aboutus.html
appears in google's cache as being from www.domain.com/aboutus.html another virtual site on the same IP.

To answer your incredulous question I have seen it, in fact I have seen most of a large (tens of thousands pages of an ecommerce site) replicated as being part of a rather small site. There were other sites on that server that were also well mixed up. They were all using relative addressing in addition to being on a shared server IP You can draw whatever conclusions you wish from that.

It is kind of hard for a fully specified identifier to be misunderstood (I'm trying very hard to be nice here).

Decius

1:16 am on Nov 30, 2006 (gmt 0)

10+ Year Member



There is nothing incredulous about this question. If one is setting up a 301 redirect function that will be used accross a set of domains it is quite a lot easier and simpler to use relative urls. Whether this can get you into trouble outside of Google is your own technical issue. The specific question is how GOOGLE reacts to it, which has yet to be addressed.

theBear

1:37 am on Nov 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And I'm telling you that leaving things to chance when you can fully specify a locator is asking other agents to insert the rest of the locator by design or error.

I also told you of a situation where relative urls were part of the mix of a mess.

If you go back into the archives of this site you'll see that at least one Google representive recommends the full specification of urls.

Why I haven't a clue but maybe they know of a gotcha.

I roll code so I love nonabsolute urls, but I have seen the results in realtime.

Oh from a site level an absolute url stops the splitting of a site along the www/non-www line of split sites.

[edited by: theBear at 1:43 am (utc) on Nov. 30, 2006]

jdMorgan

1:45 am on Nov 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> will be used across a set of domains...

I'd advise you to build s canonical URL by using either the SERVER_NAME or HTTP_HOST variable, rather than taking your chances with an HTTP response that depends on the client for resolution.

Even if someone answers authoritatively that Google will accept a relative-URL response today, that could easily change tomorrow.

Jim

jtara

1:50 am on Nov 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RFC2616 (HTTP 1.1 spec) requires an absolute URI. This is a requirement of the Location response-header field.

14.30 Location

The Location response-header field is used to redirect the recipient to a location other than the Request-URI for completion of the request or identification of a new resource. For 201 (Created) responses, the Location is that of the new resource which was created by the request. For 3xx responses, the location SHOULD indicate the server's preferred URI for automatic redirection to the resource. The field value consists of a single absolute URI.

Location = "Location" ":" absoluteURI

An example is:

Location: [w3.org...]

I think it's rather irrelevant whether Google handles an incorrectly-formed response they way you'd like them to or not.

Your PHP code is broken. It would be perfectly legitimate for the PHP library, your webserver, Google, or any client, to simply reject this and flag it as an error. And in a perfect world, they all would.

Alternately, a given web server, module, plug-in, programming library, could permit a relative URL to be given and fill in the missing part itself. You will have to look at the details of your particular server, etc. to determine that.

Bottom line is, the Location field in the HTTP response is specified as an absolute URI. The action of a given browser or spider, given an incorrect HTTP response is "undefined".

[edited by: jtara at 2:03 am (utc) on Nov. 30, 2006]

Decius

1:56 am on Nov 30, 2006 (gmt 0)

10+ Year Member



I almost always code using relative urls to give myself more freedom to specify the domain if need be (almost everything is dynamic).

But as per the information provided in this thread and the information I've found elsehwere, it seems that although there is no definite answer and relative paths "might" be all right, you are leaving it up to the user agent to fill in the domain. This is probably all right, but why take that chance.

So therein lies the difference: If you send a 301 redirect with a relative url, it is up to the user agent to decide what to put ahead of the path. If you specify, then you have a uniform redirect that cannot be incorrectly completed.

That being said if you use Google sitemaps and have specified a www or non-www preference and use a relative 301 redirect, and just found this thread and wish to switch to absolutes to be on the safe side, the chances are you didn't mess anything up by using relative urls to begin with, so there is no need to fret.

[edited by: Decius at 1:59 am (utc) on Nov. 30, 2006]

jtara

2:04 am on Nov 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I almost always code using relative urls to give myself more freedom to specify the domain if need be (almost everything is dynamic).

This is a feature of HTML. HTML explicitly permits relative URLs.

HTML!= HTTP

Redirects don't involve HTML.

theBear

3:50 am on Nov 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jtara,

Undefined is almost equivalent to random, unspecified, and highly dangerous.

I always got a chuckle out of such wording in principles of operation manuals.

Another one I always loved was the actual order of operations may not be the same as the conceptual order.

g1smd

2:23 pm on Nov 30, 2006 (gmt 0)

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



Relative URLs allow errors to creep in.

A redirect from page1.html to page2.html will work for both:

domain.com/page1.html ---> domain.com/page2.html

and for

www.domain.com/page1.html ---> www.domain.com/page2.html

In both cases you probably wanted www.domain.com/page2.html as the final result. Only an absolute URL can do that.