如何将localhost站点上传到在线服务器?

时间:2016-04-06 07:18:52

标签: php apache ftp

现在我知道你必须将文件FTP到服务器,但我对目录结构更加困惑......让我解释..

这是localhost目录结构
C:/ wamp / www / store / {这是整个项目}

这是在线服务器目录结构
htdocs / {项目将在这里}

我的问题

如您所见,项目的根目录是localhost环境中的“/ store”。所以我在代码中使用了相对路径来引用根目录,即“/ store /”。您可以看到我在整个项目中使用这种类型的引用。

print "<div class='globalerror'>
          <div class='globalerror-content'>
          <h5>Uh-oh! There's an error</h5>
          <p>You must go back</p><br/>
          <p class='back'><a href='/store/'>Go back</a></p>
          </div>
       </div>";

如果我将文件上传到“htdocs”它会给我一个错误,即找不到目录。如果我在htdocs文件夹中创建一个名为“store”的文件夹...我必须去www.mydomain.com/store(我不想要)

所以,我搞得很糟糕吗?或者有一个简单的解决方案?或者我是否必须在项目中将所有“/ store”编辑为“/”?

3 个答案:

答案 0 :(得分:0)

简单,你必须改变目录的路径。创建新目录并提供该目录的路径。因为服务器中没有目录。

答案 1 :(得分:0)

您是否尝试使用.htacess进行网址重写?

URL rewriting with PHP

如果有可能你可以更改Apache配置中的文件夹(我假设您使用Apache) Using a directory in VirtualHost ServerName

答案 2 :(得分:0)

目前您可以修改.htaccess文件并管理网址,从商店更改为根

Ref 1

Ref 2

Ref 3

最佳选择是在单个变量中设置基本URL并使用项目周围的变量。 您可以考虑以下选项,如果您愿意编辑所有链接。

<强>的settings.php

/*
Local Server = http://localhost/store/      
Online Server = http://www.example.com/
*/
$WEBSITE_URL = 'http://www.example.com/'; 

php文件

查找&amp;替换/存储/使用$ WEBSITE_URL,检查单引号/双引号

require_once('settings.php');

print "<div class='globalerror'>
          <div class='globalerror-content'>
          <h5>Uh-oh! There's an error</h5>
          <p>You must go back</p><br/>
          <p class='back'><a href='".$WEBSITE_URL."'>Go back</a></p>
          </div>
       </div>";
相关问题