cakephp 2 CSS,JavaScript和链接在本地计算机/本地主机上不起作用 [英] cakephp 2 css, javascript and links not working on local machine/localhost

查看:91
本文介绍了cakephp 2 CSS,JavaScript和链接在本地计算机/本地主机上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该在webroot文件夹上使用什么htaccess设置。

what htaccess settings should i use on the webroot folder. it seems that it's the primary culprit of why all the links in the Layout doesn't work.

这是webroot文件夹中的htaccess代码

here is the htaccess code inside the webroot folder

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

该项目来自实时服务器,但我需要使其在我的本地计算机/本地主机上工作我可以做出一些改变。但是,如您在第一张图片上所看到的,css,链接和javascript代码未加载。

the project is from the live server but i needed to make it work on my local machine/ localhost so that i can make some changes. but as you can see on the first picture, the css, links and javascript codes doesn't load.

推荐答案

您的问题是在localhost上,您的网站在Apache文档根目录的子文件夹中运行,而您的链接中没有指定此子文件夹。因此,如果文件位于 C:/xampp/htdocs/www/app/webroot/css/mysheet.css 中,则正确的访问方式为 < link rel = stylesheet href = / www / css / mysheet.css>

The core of your problem is that on localhost you are running your website in subfolder in Apache document root, and you do not have this subfolder specified in your links. So if file resides in C:/xampp/htdocs/www/app/webroot/css/mysheet.css, correct way to reach it would be <link rel="stylesheet" href="/www/css/mysheet.css">.

您在这里有两个选择,您可以(而且我认为应该)同时使用它们:

You have two options here, and you can (and I think you should) use BOTH of them:


  1. 使用HtmlHelper

在您的视图中,通过调用 $ this-> Html-> css( mysheet)链接到您的工作表,它还将包括其基本文件夹。更多信息: HtmlHelper

By calling $this->Html->css("mysheet") in your view, Cake will create link to your sheet, and it will include also its base folder. More info: HtmlHelper


  1. 使用本地域

您可以设置在xampp配置中设置本地虚拟主机。之后,您将可以使用此域而不是localhost / www访问本地网站。在下面的示例中,我将使用域mywebsite.local:

You can set up local virtual host in your xampp config. After doing so, you will be able to reach your local website using this domain, instead of localhost/www. In example below I will use domain mywebsite.local:

2.1。转到C:/ xampp / apache / conf / extra并打开httpd-vhosts.conf。

2.1. Go to C:/xampp/apache/conf/extra and open httpd-vhosts.conf.

2.2。在文件末尾添加以下代码:

2.2. Add following code to end of file:

< VirtualHost *:80>
DocumentRoot C:/ xampp / htdocs / www
ServerName mywebsite.local
< / VirtualHost>

2.3。转到C:/ Windows / System32 / drivers / etc并以管理员权限打开hosts文件。

2.3. Go to C:/Windows/System32/drivers/etc and open hosts file with admin permissions.

2.4。添加以下行: 127.0.0.1 mywebsite.local

2.4. Add following line: 127.0.0.1 mywebsite.local

2.5。重新启动Apache。

2.5. Restart Apache.

现在,您可以通过在浏览器地址栏中输入 http://mywebsite.local 。由于此虚拟主机的文档根目录现在为htdocs / www,因此所有CSS都应加载。

Now, you can access your local website by typing in your browser address bar http://mywebsite.local. As document root for this virtual host is now htdocs/www, all css should load.

这篇关于cakephp 2 CSS,JavaScript和链接在本地计算机/本地主机上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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