开发者

How to use relative URL's in website with two base URL's

I have our basic corporate static html website installed in our web root directory and our billing software installed in /portal. I have integrated the websites to look like a single site by including the /menu.tpl smarty template file in the /portal/header.tpl file. However, if I use relative URL's, the menu sysem doesnt work as the base url for the billing script is /portal. i.e. if I create a link to faq.php in the menu.tpl and I load a page on the portal site, the link in the menu back to the开发者_如何学编程 faq page is now /portal/faq.php whereby if I load a page off the root site the link is just /faq.php as it should be.

The obvious answer is to just use absolute URL's, but I need the site to be portable as I have many developers who need to install and test it.

I cant find anyway to resolve this. Any ideas?


I ran into the same problem as you a while ago, and after trying a lot of dead ends, I finally ended up with the following solution:

  1. For any URL you need to be a chamelion, i.e. change its path depending on the environment, insert a PHP function that writes out the correct URL.
  2. If you include the PHP function from a single central file, then you can change all of the URL's in the entire site automatically, based on a setting, or some pre-detected switch such as the current domain name, etc.

Example:

<?php print_base_url_plus("/menu.php"); ?>

... where print_base_url_plus() is a function which appends the base URL onto the output.

You may find that you have to change some of the URL's to be php, so they are preprocessed by the PHP engine, or, you can alter the web settings so that standard .htm files are piped through the PHP engine, just like .php files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜