1. Whats the use of 301 redirect and how to do that?

It tells web browsers and search spiders that you've reorganized your site, and that the item they were looking for is at a new location, and they should stop looking at the old location.

As for how to do it, the code you gave _should_ do what you're attempting to do, but the fact that it's displayed by the browser leads me to suspect that something else has already generated an HTTP header. You may need to contact your webserver administrator to see if they have some sort of a wrapper that you're running under.

2. Do I require any Apache setting OR .htaccess setting?

Not typically, but if the server is set up to wrap the CGIs, and insert HTTP headers, you're going to need to shut that off for this script. As it's not a typical thing for servers to do, and there's more than one way to implement wrappers, you're going to need to talk to the administrator of the webserver you're running this on.

3. Why I can't simply do "Http-Equiv=refresh" or print "Location:http://www.mydomain.com/page.html\n\n" for the same task?

Well, the two methods that you are asking about are similar to each other, but fundamentally different from a 301. Basically, if you do that, you're telling the web browser that the location right now is at some other place, but nothing about the URL that they had asked for -- so they're likely to come back again, and then be redirected.

Meta refresh or a 302 request (which is typically assumed if you send a location and no status) should not be cached by proxies, and so any subsequent requests for that page should call the CGI every time they want the page, to find out if the redirection has ended or changed location.

If you're trying to track entry points to the same resource, you might want this extra overhead. Personally, I use 302s as a convenience thing for a few URLs -- I have a 'latest' URI, which redirects the user to the most recent item. (although I could just serve it directly, we had a problem with people trying to share the 'lastest' URI, which would updated to a new item before they recipient followed the link). In this case, I _want_ the user to continue using the 'latest' URI to get the latest item, but I don't want them associating the URI with a specific item.


In reply to Re: 301 Redirect using Perl by jhourcle
in thread 301 Redirect using Perl by siva kumar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.