如何在具有两个基本 URL 的网站中使用相对 URL

发布于 2024-10-05 02:06:17 字数 374 浏览 0 评论 0原文

我将基本的企业静态 html 网站安装在 Web 根目录中,并将计费软件安装在 /portal 中。我通过在 /portal/header.tpl 文件中包含 /menu.tpl smarty 模板文件,将网站集成为看起来像单个站点。但是,如果我使用相对 URL,菜单系统将不起作用,因为计费脚本的基本 URL 是 /portal。即,如果我在 menu.tpl 中创建指向 faq.php 的链接并在门户网站上加载页面,则菜单中返回 faq 页面的链接现在为 /portal/faq.php,如果我加载页面根站点的链接应该是 /faq.php 。

显而易见的答案是只使用绝对 URL,但我需要该网站是可移植的,因为我有许多开发人员需要安装和测试它。

无论如何我找不到解决这个问题的方法。有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与君绝 2024-10-12 02:06:17

我前段时间遇到了和你一样的问题,在尝试了很多死胡同之后,我最终得到了以下解决方案:

  1. 对于任何你需要成为变色龙的URL,即根据环境更改其路径,插入写出正确 URL 的 PHP 函数。
  2. 如果您包含来自单个中央文件的 PHP 函数,那么您可以根据设置或某些预先检测到的开关(例如当前域名等)自动更改整个站点中的所有 URL。

示例:

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

..其中 print_base_url_plus() 是将基本 URL 附加到输出的函数。

您可能会发现必须将某些 URL 更改为 php,以便 PHP 引擎对它们进行预处理,或者您可以更改 Web 设置,以便通过 PHP 引擎传输标准 .htm 文件,就像 .php 一样文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文