I have a long list of URL, all in the same format
[site1.com...] (URL-a)
Each URL will be relocated to another URL, say, [FooSite.com...] (URL-b٩
Now, I want to write a program to record all URL-a to its destinaion URL (URL-b) and save them in MySQL.
I'm new to Perl. Could anybody tell me briefly how to do that? Shall I use a foreach loop and then use Perl:CGI module to get HTTP head info or shall I..?
Thanks!
---------
#!/usr/bin/perl
##### STORE YOUR DATA INTO ARRAYS #####
$sourceURLS = (
"http://****.com/1",
"http://****.com/2",
"http://****.com/3"
);
$destinationURLS = (
[yyy.com...]
[yyy.com...]
[yyy.com...]
);
##### SET THE CGI ######
use CGI;
$cgi = new CGI;
##### OPEN THE DATABASE ######
use DBI;
$host_name = 'hostname.com'; # fill in your own data for these
$database = 'databasename';
$DBuser = 'username';
$password = 'password';
$table = 'tablename';
#Open connection and establish object
$DB = DBI->connect("DBI:mysql:$database:$host_name", $DBuser, $password);
#### WRITE THE DATA TO THE DATABASE ###
for $counter (0..#$sourceURLS) {
$DB->do("INSERT INTO $table VALUES ('$sourceURLS[$counter]','$destinationURLS[$counter]')");
}
For instance, the SourceURL is www.site.com/link.pl?id=1 and the destinationURL is www.webmasterworld.com
I wonder shall I use LWP to send a request and get response and get the DestinationURL from http header information?
Many Thanks!
What I want to do is to get a URL (destination URL) by reading another URL (Source URL).
I have a long list of source URL (all in the same format: htttp://www.mysite.com/link.cgi?id=N). If I input one source URL in IE address bar, the page will be relocated/forwarded to another URL(the destination URL).
Because the list has 9000+ source URLs, so I want to write a Perl script to read source URL line by line and get its destination URL.
I am new to Perl and I am not sure if it should be done this: Use LWP to send a request and get response. Get destination URL information through the response HTTP:header. If it's the right path, I will try to do that myself, just borrowed several books from the library. :)
Thank you again!
If I input one source URL in IE address bar, the page will be relocated/forwarded to another URL(the destination URL).
Okay, there's your problem, you shouldn't be using Perl for this, you should put the redirect commands in your <.htaccess> file. That file is at the top level of your domain directory (same level as index.html). If it's not there then just create one. Then put these commands into it:
Redirect 301 /url1.html [newdomain.com...]
Redirect 301 /url2.html [newdomain.com...]
Note that the source url is listed without the http:// but the destination is.
Since you started off by asking about Perl and MySQL, I thought that's what you needed help with. But now that I see what you want to do, you should steer far clear of Perl and MySQL for this task.