1

I have a php file containing my navbar(menu.php) which is used from many of my pages. Let me show you my folder structure:

index.php

html
   menu.php
   apps
       app1.php
       app2.php
   webdesign
       html.php
       js.php

and the following code: <

div class="navbar navbar-inverse navbar-static-top navbar-topic">
            <div class="container">
            <div class="navbar-header"><!--navbar start-->
                <a  href="http://kounj.web44.net"  class="navbar-brand"><!--Logo -->
                    iloveprogramming
                </a>
                <button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
                    <span class="icon-bar"></span><!--4 icon-bar spans create the dropdown menu-->
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>

                </button>
            </div>
                <div class="collapse navbar-collapse navHeaderCollapse">
                    <ul class="nav navbar-nav navbar-right">

                        <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Web Design <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            <li><a href="/webdesign/html.php">Html</a></li>
                            <li><a href="/webdesign/css.php">Css</a></li>
                            <li><a href="/webdesign/js.php">Javascript</a></li>
                            <li><a href="/webdesign/php.php">PHP</a></li>

                        </ul>


                        </li>
                        <li><a href="/apps/index.php">Tools</a></li>
                        <li><a href="/contact.html">Contact</a></li>
                    </ul>
                </div>
            </div>
        </div><!--navbar end-->

The problem is that when i use index.php which is on the root folder my links on navbar will not be set correctly.Any ideas

4
  • are you using any localserver? Commented Dec 17, 2014 at 0:52
  • your links should be from your root directory and not from the current file location Commented Dec 17, 2014 at 1:00
  • Where does your server's document root point? Commented Dec 17, 2014 at 1:15
  • Check this answer to get an Url from a path stackoverflow.com/a/36101073/3626097 Commented Jun 17, 2016 at 12:33

1 Answer 1

1

You can either use absolute path by setting a constant in menu.php that might look like this:

define("ROOTPATH", "/var/www/html/apps/");

(A quick and dirty approach, but effective) for your Navigation links and setting them like so:

<a href="<?php echo ROOTPATH; ?>/app1.php</a>
<!-- etc -->

Or you can edit you Apache http.conf file thereby pointing it to your PHP projects root folder, and restart apache to get your changes to take effect. But both will address your PHP file path issues.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.