Forum Moderators: coopster

Message Too Old, No Replies

help? resolve "/" to "/index.php"

i'm thinking this might be built-in

         

httpwebwitch

5:50 pm on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I need to resolve URLs on the server for a tracking script.

For instance if I have a string like "http://mydomain.com/", I want to change it to "http://mydomain.com/index.php" (or whatever the proper file name is).

can PHP resolve aliased pages and URL shortcuts to the proper URL?

crashomon

5:58 pm on May 21, 2004 (gmt 0)

10+ Year Member



Hi, if you're running apache, you need to set up the redirects to make this happen. Its a matter of modifying the conf files (if you don't know what this is, maybe you can use the next tip instead)

If you currently have an index.htm or index.html, you can simply use meta redirects to index.php . Check on google for how to do this.

Check with your network administrator to set up your web server to deliver index.php as your default index page.

good luck,

Patrick Elward

bakedjake

6:02 pm on May 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Do you want www.mydomain.com/ to SERVE index.php transparently, or REDIRECT to index.php?

I think you want to SERVE it, in which case you want to use the DirectoryIndex directive.

httpwebwitch

6:07 pm on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No no, neither of the above.

I have thousands of URLs stored in a database. They need to be compared to each other for statistics. Some are like this: "mydomain.com/",
some are like this: "mydomain.com",
and others are like this: "mydomain.com/index.php"

The same is happening with hundreds of subdirectories, like "mydomain.com/stuff/" and "mydomain.com/stuff/index.htm"

What I need is a way to change them all into the verbose proper URI, with a string function, in the simplest way possible.

httpwebwitch

6:08 pm on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



more clearly, I am neither serving nor requesting these URLs, I'm just comparing them as strings.

httpwebwitch

6:27 pm on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've tried different combinations of parse_url, basename, etc.

parse_url("http://www.mydomain.com");

returns:
Array ( [scheme] => http [host] => www.mydomain.com [path] => / )

but it doesn't fill in the missing "index.php" file name that I need to complete the URL.

So... none of the built-in functions I've found are doing the job. I think I might need to request the file from the server (in a hidden way) and parse what's returned? Is that possible?

your advice is highly appreciated

jatar_k

6:28 pm on May 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



a few rules then

if it ends in com 
add / + default page name
if it ends in /
add default page name
else
leave it

is that what you mean?
do you have a single default page name?
or do you have .htm, .html, .php variants all over?

httpwebwitch

6:40 pm on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Those rules will work in most situations, yes. However there are some subdirectories using "index.htm" and others using "index.php". In this particular application, those are the only 2 file names being used, but I'd like this function to be more robust, able to handle cases of "default.html" and "index.asp" and "myhomepage.php3"... these are defined at the server and my script is too dumb to figure out the right one to add.

I think the answer I need will involve sending a request to the server, letting it serve up the correct default page, then parsing the returned result. I wonder if I can grab $HTTP_SERVER_VARS from a page loaded with "fsockopen()" or something like that? I'm not sure where to start with that idea, but wouldn't it make a nice all-purpose function to have in the PHP library?

The result will be a nice "resolve_real_URI" function that goes beyond the basic string splitting functions offered in PHP.

I'm still hacking away...

jatar_k

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

WebmasterWorld Administrator 10+ Year Member



in the tracking script itself why not get full urls as opposed to doing it after the fact? or is it just running off of apache logs?

httpwebwitch

7:07 pm on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks jatar_k! good idea, and actually I just did that, so all my new data is being stored with the SCRIPT_NAME appended.

I'm still left with all this legacy data that has been accumulating for months and months... Any ideas how to resolve a URL into its verbose form by hitting the server with a request?

jatar_k

7:14 pm on May 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I can think of some manual ways to do it actually

parsing the directory structure and storing all fully qualified script names, then cross referencing your partial data with the actual list of pagenames.

if index.php is the most common, making an array of dirs that have other default page names and using that to qualify partials

it really depends, if everything is all over the place then the first may be the most reliable.

This is just legacy data conversion so the key is accuracy not speed or ease.

httpwebwitch

4:15 pm on May 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks for all your advice so far.

Though it took a lot of manual effort, I replaced all the old values with new "verbose" ones by looking up things on the server and doing some search/replace work.

I still wish there was a built-in or cookbook solution for that problem, but I'll put it aside for now since all my legacy data has been converted the "hard way".