Jump to content

linking your pages


jcombs_31

Recommended Posts

I was reading an article and it brought up something interesting.  How do you link your pages?  Do you use the absolute path with http://www.something.com/page1.php

 

or do you use the relative path /page1.php

 

?

 

I've always used a relative path, does it matter and what do you do?

Link to comment
https://forums.phpfreaks.com/topic/50921-linking-your-pages/
Share on other sites

i never use the URL in my hyperlinks unless it's linking externally. It has been known for me to change domain names for a project and I'm not a fan of either using php to insert the domain (i tend to keep my HTML pages as HTML as possible) or search+replace+re-upload in the event of me changing the domain name (or going from a testing server to a proper one)

 

I dislike syntax such as ./somewhere/test.php or ../somewhereelse/test2.php so I always start my links off with a / so they're all relative to the web root.

Link to comment
https://forums.phpfreaks.com/topic/50921-linking-your-pages/#findComment-250464
Share on other sites

Always relative. I try and make my sites as portable as possible. I.e they will run under a subdomain or a subfolder of a domain name, i.e. http://project.website.com or http://www.website.com/project.

 

I also think google prefers relative links for SEO stuff.

 

-steve

Link to comment
https://forums.phpfreaks.com/topic/50921-linking-your-pages/#findComment-251389
Share on other sites

I keep my dynamic. There are times when I need to get links that are controlled by cpanel to work on their directory and not the root.  Sounds confusing, but here is what i do:

 

<?php

 

$path = "..";

 

$link = $path . '/index.php';

 

echo $link;

 

require_once($path . 'includes/master.php');

 

unset($path);

 

?>

 

stuff like that :-/

Link to comment
https://forums.phpfreaks.com/topic/50921-linking-your-pages/#findComment-253266
Share on other sites

I like creating things dynamic. That's why I use relative paths. And even if I need to use a full address (like in an email for confirming a registration or something like that) I do things like this:

 

<?php

$url = "http://".$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF'])."/activation.php";

?>

 

This makes things dynamic as possible.

 

Orio.

Link to comment
https://forums.phpfreaks.com/topic/50921-linking-your-pages/#findComment-253383
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.