URL路径本地工作,但不在服务器上 [英] URL paths work local but not on server

查看:156
本文介绍了URL路径本地工作,但不在服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数在我的项目的URL链接(CSS,图片,js文件等)是绝对的,但这些不是我的服务器上运行。
我已经位于我的子文件夹服务器上的项目,所以它会在根目录下。

Most of the URL links (css, images, js files etc) in my project are absolute, but these don't work on my server. I've located the project on my server in a subfolder, so it is going to the root.

我怎样才能改变此状 /images/background.jpg 的URL将会 123.12.34.56/projectfolder/images/background。 JPG 而不是 123.12.34.56/images/background.jpg

How can I change this so the url like /images/background.jpg is going to 123.12.34.56/projectfolder/images/background.jpg instead of 123.12.34.56/images/background.jpg?

我猜它是与Apache的配置,但我无法找到它尚未...

I guess it has something to do with Apache config, but I couldn't find it yet...

,也许还有一些 laraways 来解决这个问题。

I'm using Laravel, so maybe there are some laraways to fix this.

推荐答案

我最常做的是创建一个子域(cdn.example.com),它指向一个叫做资产目录这是在同一水平的公目录。我所有的JS,图像,CSS都在那里。

what i usually do is create a sub domain (cdn.example.com) and point it to a directory called assets which is in the same level as the public directory. All my js, images, css are in there.

然后在app.config中添加一个新的键值对'CDN'=>' HTTP://cdn.example。 COM 。当我加入CSS或js文件我使用它是这样的。

Then in the app.config add a new key value pair 'cdn' => 'http://cdn.example.com'. When i'm adding css or js files i'm using it like this.

<script src="<?php echo Config::get('app.cdn') ?>/js/jquery/1.7.1/jquery.min.js"></script>

为什么这样做?说,如果我决定我的资产转移到一个高速缓存服务器,我可以很容易地通过移动只是cdn.example.com

Why do this? say if i decide to move my assets to a caching server i can easily do so by moving just the cdn.example.com

这篇关于URL路径本地工作,但不在服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆