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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |