Forum Moderators: coopster

Message Too Old, No Replies

URL help

         

makochild

1:46 am on Oct 25, 2004 (gmt 0)

10+ Year Member



I'm trying to make a template for my site and in this template, I want to make my links like "/contact/" but i want it to load contact.php and not look for a folder called contact.

I cant seem to find anything on this anywhere.

Can anyone help me?

thanks in advance.

coopster

2:41 am on Oct 25, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, makochild.

It seems as though you may be looking for Apache's mod_rewrite [httpd.apache.org] module. Or are you looking for something in PHP? The Apache module fits exactly what you are asking for, though...

kpaul

2:51 am on Oct 25, 2004 (gmt 0)

10+ Year Member


is there a reason you don't want to name it index.php?

if you do so, there's a good chance when someone browser /example/ they'll default to index.php

welcome and all that ;[smilestopper])

-kpaul

makochild

7:00 pm on Oct 25, 2004 (gmt 0)

10+ Year Member



Coopster, if it can be done in php then i would like it in php. I'm not familiar with the apache mod rewrite

I'm doing this becauase it's a matter of personal preference.

If I cant get it done then I guess I'll stick with making regular links (i.e. contact.php)

kpaul

8:46 pm on Oct 25, 2004 (gmt 0)

10+ Year Member



also note that Google will see:

/directory/

and

/directory/category.php

as two different pages...

-kpaul

robho

9:46 pm on Oct 25, 2004 (gmt 0)

10+ Year Member



Assuming you're using Apache you can add the following line in the Apache httpd.conf (supposed to also work in .htaccess files, I don't use those):

DefaultType application/x-httpd-php

This means any files without an extension are served as php.

I use this for several sites.

So just rename your contact.php to contact, and the parameters after it will be in PATH_INFO. (e.g. /contact/my/pages/ will have "/my/pages/" in PATH_INFO which you can then use to decide what to display). The last slash may not always be present depending on how the url was typed.

Rob

makochild

2:49 am on Oct 26, 2004 (gmt 0)

10+ Year Member



thanks robho

would have never thought of using a .htaccess file to do what i needed.

makochild

4:18 am on Oct 26, 2004 (gmt 0)

10+ Year Member



well, i noticed that the links would have to be like [example.com...] for my templates to work right if i have the links as
[example.com...] then the templates wont include my files that need to be included for the layout (you can still see the content).

[edited by: jatar_k at 4:37 am (utc) on Oct. 26, 2004]
[edit reason] generalized urls [/edit]

robho

10:49 am on Oct 26, 2004 (gmt 0)

10+ Year Member



the templates wont include my files that need to be included

Works fine for me with our without the slash, maybe it's something to do with the way you handle the path_info within the script (or does the path of the include depend on one of the parameters?).

I do this sort of thing to get a consistent result (on a script that only has a single parameter):


$path_info = $_SERVER["PATH_INFO"];
if (!$path_info) {$path_info = $_SERVER["SCRIPT_URL"];};
$path_info = trim($path_info,'/');
$parm = strip_tags(trim($path_info));

Can't remember why I do the Script_url bit but it's there for some reason and doesn't seem to do any harm. :-)