skip to Main Content

I’m working on a project with some friends that needs a little website I’m developping.

It’s host on my computer using Wamp server, and I configured it this way :

  • C:wamp64wwwprojectfolder is the folder where my project is.
  • http://example.online/ is the virtual host pointing to my projectfolder that I use to access my website locally.
  • http://example.ddnsservice.org/projectfolder/ is the URL to access my website whenever I need to share it.
  • http://example.ddnsservice.org/ i.e. points to the default wampserver page.

Working this way, all the relative links pointing to / or /something/else/ are working when I use my virtual host URL but don’t when I use the public URL. /models/ would redirect to http://example.ddnsservice.org/models/ instead of http://example.ddnsservice.org/projectfolder/models/.

I’ve tried to use RewriteRule on the .htaccess file in projectfolder following several solutions proposed here but nothing seemed to work so I begin to think that I have a deep misconception of what hosting a website should look like. The last thing I tried was:

RewriteEngine on
RewriteCond "%{HTTP_HOST}" "^(.*)example.ddnsservice.org(.*)$"
RewriteRule ^/$ ^/projectfolder/$

I didn’t try to make http://example.ddnsservice.org/ point to the projectfolder because I sometimes share others projects and because I don’t know how to do it.

I’m pretty lost atm and don’t really know from where to take this problem anymore.

Thanks everyone for reading me and giving a bit of your time.

— EDIT —

For a bit more details, those are the links messing up with me. Or I’m messing up with them, can’t say! (I’ve just let the <a> tags)

  <a href="/?action=session_destroy">session_destroy();</a>
  <a href="http://localhost">LOCALHOST</a>
  <a href="/">ROOT</a>
  <a href="/admin/">ADMIN</a>
  <a href="/admin/?action=testPage">TEST_PAGE</a>
  <a href="/?action=empty_session_key">$_SESSION['key']="";</a>
  <a href="?">EMPTY GET</a>
  <a href="?key=<?= $key['display_key'] ?>">KEY1</a>
  <a href="?key=<?= $key['forum_key'] ?>">KEY2</a>

I realised reading your answers that I’m getting myself in difficulty. I don’t need to host several projects at once so I could just configure Apache to point to my projectfolder by default. I also thank a lot @BURN-ADDiCT for his personnalized tutorial as I can’t do it by commenting if I understand the rules right.

I also realized that my choice to separate some restricted operation on my database in /admin/index.php may be a bad idea, that’s what causes me to use links relatives to the website/server root and I’ll change this.

I’ll work on this whenever I have enough freetime but for now the problem is fixed by the apache configuration solution. Thanks everyone for your time.

2

Answers


  1. Don’t use the / as prefix in your links.
    Let’s say your server has a folderstructure like this:

    htdocs (public-html)
      |- projectfolder
           |- images
                - logo.png 
                - photo.jpeg
           - index.html
    

    So you want to link from the index to a different file. In your question a model for example, or in the situation above to an image. In this case you need to link to "images/logo.png". As your index is located in the projectfolder already it will search from this location to a folder images and then enters the folder and looks for the logo.png. So the url would translate to http://example.ddnsservice.org/projectfolder/images/logo.png

    If you would use "/images/logo.png" you’re telling that it needs to move up one folder and start to search from there. As your index is located in the projectfolder, it will move folder up, to the htdocs (or public-html or something) and search from this location to a folder images and then tries to enters the folder and looks for the logo.png. So that url would translate to http://example.ddnsservice.org/images/logo.png And that folder is the wrong folder, in this case it doesn’t even existed.

    Login or Signup to reply.
  2. The answer from @t-s should solve your main problem. It’s a matter of relative referencing. I am now editing my answer to help with some of the other parts of your post since I now have better understanding of what you don’t understand.


    I didn’t try to make http://example.ddnsservice.org/ point to the projectfolder because I sometimes share others projects and because I don’t know how to do it.

    If you wanted to do this, you would need to change Apache default settings, like in this answer: https://stackoverflow.com/a/5891858/10335389

    It will be a platform specific thing, but you basically need to locate the httpd.conf file, which might be under wamp/apache2/conf/ for you since you use Wamp.
    In that file, find the DocumentRoot setting and append "/projectfolder" to the value. You will probably find it as c:wamphtdocs, and you change it to c:wamphtdocsprojectfolder.
    Make the same change to the <Directory "c:wamphtdocs"> setting (which should be on the next line).


    I sometimes share others projects

    For this, you can set up multiple virtual hosts. I have not used this myself so I wont say much about it. I am only sharing this in case you are interested in making your projectfolder the root, and later want to share a different project (also as root).

    In case you don’t need the sites to be running simultaneously, then you can use symbolic links for (since I use Linux, they’re easy to do), but on Windows, you might want to either use aliases to make the "projectfolder" point to a different folder each time, OR, only keep a copy of the project you want to serve in "projectfolder".
    In my opinion, the latter is convenient.


    I’ve tried to use RewriteRule on the .htaccess file in projectfolder following several solutions proposed here but nothing seemed to work so I begin to think that I have a deep misconception of what hosting a website should look like.

    This would not a good way to go about this even if it did concern your problem.

    According to the Apache docs (under the "When (not) to use .htaccess files" section):

    you should only use .htaccess files when you don’t have access to the main server configuration file.

    It further goes on to say:

    in general, use of .htaccess files should be avoided when possible. Any configuration that you would consider putting in a .htaccess file, can just as effectively be made in a <Directory> section in your main server configuration file.


    I hope this helps, even though the problem was just a matter of relative referencing.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search