如何在具有两个基本 URL 的网站中使用相对 URL
我将基本的企业静态 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我前段时间遇到了和你一样的问题,在尝试了很多死胡同之后,我最终得到了以下解决方案:
示例:
..其中 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:
Example:
... 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.