Forum Moderators: coopster & phranque

Message Too Old, No Replies

Getting a URL by inputing another URL

         

ebizcamp

7:38 pm on May 24, 2004 (gmt 0)

10+ Year Member



Hi,

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!

ebizcamp

7:46 pm on May 24, 2004 (gmt 0)

10+ Year Member



"record all URL-a to its destinaion URL (URL-b)" seems confusing. What I want to say is to record allURL-a's desitination URL (URL-b)

MichaelBluejay

9:06 am on May 25, 2004 (gmt 0)

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



You just want to use Perl to get some data into MySQL? Is that what you're asking? I'm not sure... If that's what you want, then here's one way to do it, assuming you have a MySQL database set up with two fields, one for old URLS and one for the new URLS:

---------
#!/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]')");
}

ebizcamp

6:43 pm on May 25, 2004 (gmt 0)

10+ Year Member



MichaelBluejay,

Many thanks.

ebizcamp

7:51 pm on May 25, 2004 (gmt 0)

10+ Year Member



Could you please suggest how to get Destination URL from SourceURL?

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!

MichaelBluejay

9:41 pm on May 26, 2004 (gmt 0)

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



I don't understand what you're asking, or what it is you're ultimately trying to do. Are you trying to find the REFERERS to a specific page? Please be very specific.

ebizcamp

7:00 pm on May 27, 2004 (gmt 0)

10+ Year Member



Sorry for that.

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!

MichaelBluejay

9:42 am on May 28, 2004 (gmt 0)

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



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.