0

I'm trying to set up a virtual host with MAMP for mac.

I'm doing this, because we need to have root relative urls for our project, but I just can't get the root relative links to work.

We are including a footer.php file on an index.php file like this:

<? include('/master/footer.php') ?> 

But the / before master does not work, and this is what I need to fix.

Below is what I have done so far. Hope someone can help me out.

MAMP - httpd-vhosts.conf:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "/Applications/MAMP/htdocs/"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Applications/MAMP/htdocs/template/"
    ServerName template.localhost
</VirtualHost>

MAMP - httpd-conf:

Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

My port is set to 80 on MAMP and I have restarted it :)

Mikkel Madsen
  • 347
  • 2
  • 5
  • 17
  • Sorry, but it is completely unclear what you ask... – arkascha Sep 22 '16 at 08:05
  • Not really. What is it that does not work as expected? The `include` command? You do _not_ use a relative path there, but an absolute one. What is `/master`? – arkascha Sep 22 '16 at 08:06
  • We could, but I have no saying in that, and the need is a / before everything like css, images, includes etc. When I go to my http://template.localhost the index's content is shown, but not the footer and header content. – Mikkel Madsen Sep 22 '16 at 08:09
  • 1
    What kind of statement is that? "the need is a / before everything"? Now do you want things to work or obey commands? What is the sense in that? Absolute paths like that make code non-portable. And I cannot see a reason for such a decision. – arkascha Sep 22 '16 at 08:10
  • BTW: you miss interpreted my comment two up. I stated what I see, not what you should do. – arkascha Sep 22 '16 at 08:11
  • 1
    PHP's include directive doesn't have anything to do with Apache's document root. You can't set the include directive's root directory this way. – JJJ Sep 22 '16 at 08:12
  • Possible duplicate of [root path doesnt work with php include](http://stackoverflow.com/questions/1400795/root-path-doesnt-work-with-php-include) – JJJ Sep 22 '16 at 08:13
  • Thank you for bashing some sense into me ;) I didn't know the thing with include, thank you.. It works as it should now. Thank you arkascha and JJJ. – Mikkel Madsen Sep 22 '16 at 08:15

0 Answers0