[英]Define base url for laravel application
My client's application is temporarily running on my staging server ( my-domain.com
), while on his server ( client-domain.com
) I placed an .htaccess
file to redirect all requests to my staging server. 我客户端的应用程序暂时在我的登台服务器(
my-domain.com
)上运行,而在他的服务器( client-domain.com
)上,我放置了一个.htaccess
文件以将所有请求重定向到我的登台服务器。 This works fine so far except when building URLs with Laravel's helper. 到目前为止,除了使用Laravel的帮助程序构建URL之外,此方法都可以正常工作。
When I call {{ action( 'Controller@getIndex' }}
for instance, Laravel returns my-domain.com/index
(instead of the desired client-domain.com/index
). 例如,当我调用
{{ action( 'Controller@getIndex' }}
,Laravel返回my-domain.com/index
(而不是所需的client-domain.com/index
)。
For now I solved this by replacing these calls with absolute, hard coded urls but that is disturbing my workflow. 现在,我通过将这些调用替换为绝对的,硬编码的URL来解决了此问题,但这困扰了我的工作流程。
So, is there a way to force Laravel to use a specific base url? 因此,有没有办法强迫Laravel使用特定的基本网址?
Laravel generate url for the current domain it is running on. Laravel为运行它的当前域生成URL。 Currently, laravel is running on my-domain.com even if you are calling it using client-domain.com.
目前,laravel在my-domain.com上运行,即使您使用client-domain.com进行调用。 That depend on how you are redirecting of course.
当然这取决于您如何重定向。
So, firstly why are you redirecting the client domain to your server. 因此,首先,为什么要将客户端域重定向到服务器。
If it's a permanent redirection, then it's better for you to: 如果这是永久重定向,那么最好执行以下操作:
If it's just for testing/debugging (or whatever) and this redirection will go away when you will move into production stage, you don't have to worry about that: 如果仅用于测试/调试(或其他),并且当您进入生产阶段时此重定向将消失,则不必担心:
On a side note, it's not really recommended to have the same content accessible with multiple urls. 附带说明一下,实际上不建议通过多个URL访问相同的内容。 So, you have to 301 redirect one domain to the other (seems to be the current behavior) and then use only one of them.
因此,您必须301将一个域重定向到另一个域(似乎是当前行为),然后仅使用其中一个。
Edit: and to answer you last question, there is no way to set the base url in laravel (for now at least). 编辑:并回答您最后一个问题,没有办法在laravel中设置基本URL(至少现在是这样)。 There seems to be an issue on github about that (here: https://github.com/laravel/framework/issues/92 ).
github上似乎有个问题(在这里: https : //github.com/laravel/framework/issues/92 )。 Maybe you can investigate in that direction, but I don't think it'll be implemented one day because that seems to be hacky and quite uncommon in any regular web application.
也许您可以朝这个方向进行调查,但是我认为不会一天实现,因为在任何常规的Web应用程序中这似乎都是很棘手的事情,而且很少见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.