Jump to content

[SOLVED] Create base URL variable?


vynsane

Recommended Posts

I have a site that can be accessed through multiple URL avenues:

 

www.WallCrawlersWeb.com

 

is also

 

www.SpideyDatabase.com

 

and

 

Spider-man.Comics-Database.com

 

because of folder structure and such, I can't use relative paths to links, and need to use absolute paths, but don't want to redirect to only one URL (the way I have been up until now.)

 

Is there a way to create a variable like

 

$BaseHref

 

that I can populate with the URL that the visitor has in their address bar INCLUDING the one utilizing a sub-domain? I found this page on the drupal site

 

http://drupal.org/node/6554

 

that might work - just don't know if it will work on the sub-domain version.

Link to comment
https://forums.phpfreaks.com/topic/40748-solved-create-base-url-variable/
Share on other sites

Thanks for the quick reply, but due to my server structure, that won't work - it's complicated... the entire website in question is in the folder "spider-man" in the folder "comics-database". My main URL is actually totally unrelated, www.vynsane.com - that's my document_root. basically to get to my spider-man site, you have to go to

 

public_html/comics-database/spider-man/

 

so I need a more round-about way of doing it...

 

 

found that this works, even with a sub-domain:

 

$baseURL = $_SERVER['HTTP_HOST'];

 

FYI, anyone who needs to do this - you have to put the 'http://' in front of your echoed variable before it will work, like this:

 

<?php
$baseURL = $_SERVER['HTTP_HOST'];
?>

<a href="http://<?php echo $baseURL ?>">Home</a> | <a href="http://<?php echo $baseURL ?>/news">News</a> | (etc.)

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.