简体   繁体   中英

How do I upload my localhost site to an online server?

Now I know that you have to FTP the files to the server but I'm more confused about the directory structure... Let me explain..

Here is the localhost directory structure
C:/wamp/www/store/{Here is the entire project}

Here is the online server directory structure
htdocs/{The project will go here}

My problem

As you can see, my root directory for the project is "/store" in the localhost environment. So I used relative path in my code to refer to the root directory which is the "/store/". You can see that I use this type of referencing throughout the project.

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>";

If I upload the files to "htdocs" It will give me an error, which is, Directory not found. If I create a folder named "store" inside the htdocs folder... I'd have to go www.mydomain.com/store (which I don't want)

So, did I messed up pretty badly? Or is there a simple fix? Or do I have to edit all the "/store" to "/" in my project?

Simple, You have to change path of directory. Create new directory and give the path of that directory. Because there is no directory in your server.

Have you try URL rewriting with .htacess ?

URL rewriting with PHP

If it possible you could change the Folder inside Apache configuration( i presume you use Apache) Using a directory in VirtualHost ServerName

Currently you can do modify the .htaccess file and can manage urls, change from store to root

Ref 1

Ref 2

Ref 3

The best option is to set the base url in single variable and use the variable around the project. You can consider the below option, If you are willing to edit the all the links.

settings.php

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

The php files

Find & Replace /store/ with $WEBSITE_URL , check the single/double quotes

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>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM