编写跨环境传输的URL的安全方法 [英] Safe way to write URLs that transfer across environments
问题描述
我目前正在本地计算机上开发一些软件.为了这个问题,让我们调用软件StackOverflow
.我有以下页面
I am currently developing some software on my local machine. For the sake of this question, lets call the software StackOverflow
. I have the below pages
C:\sites\StackOverflow\index.php
C:\sites\StackOverflow\content\page1.php
C:\sites\StackOverflow\content\page2.php
C:\sites\StackOverflow\content\page3.php
在我当前的环境中,http://localhost/StackOverflow/index.php
可以成功运行.我为内容页面编写的URL看起来类似于http://localhost/StackOverflow/content/page1.php
.
In my current environment going to http://localhost/StackOverflow/index.php
works successfully. And the URL's I've written for the content pages would look similar to http://localhost/StackOverflow/content/page1.php
.
当我将其部署到生产环境时,URL将不再是本地主机,而是IP或尚未确定的主机名.我应该如何编写URL,以便在部署时尽可能少地做些工作?
When I deploy this to production however the URL will no longer be local host but rather an IP or a hostname that has yet to be decided. How should I be writing my URLs so that I have to do as little work when I deploy as possible?
推荐答案
相对于根目录启动它们:/
.
Start them relative to the root: /
.
例如:
/StackOverflow/index.php
/StackOverflow/content/page1.php
/StackOverflow/content/page2.php
/StackOverflow/content/page3.php
They will automatically be prefixed with the current domain or whatever you set as the <base>
.
这篇关于编写跨环境传输的URL的安全方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!