0

Hello i recently just got my web server to run all .html files as .php files which now allows me to use the php include function, which is very useful.

However i have multiple sub directories with multiple files in each.

Homepage --banners --banner2.html --banner2.html --signs --sign1.html

and so on. The problem here is im trying to use include for my top nav bar. when i include the bar in the sub files, for example banner2.html it wont correctly link.

nav.php

<ul class="nav navbar-nav">
                    <li>
                        <a href="about.html">About</a>
                    </li>
                    <li>
                        <a href="Services.html">Services</a>
                    </li>
                    <li>
                        <a href="index.php">Contact</a>
                    </li>

                    <li>
                        <a href="Login/Sign-In.html">Login</a>
                    </li>

                    <li>
                        <a href="Login/logout.php">Logout</a>
                    </li>

                    <li>
                        <a href="PHP/Cart.php"><img src="images/Cart.gif" style="height: 20px; width:20px;"> Cart</a>


                    </li>

                </ul>

in the nav bar is a link to about.html normally i would do the

<a href="../about.html">about</a>

however i cant do that when every file is going to share the same navigation bar. How can I fix this?

3 Answers 3

1

I have answered my own quest and feel silly for even asking the question. I just used absoulte paths

nav.php

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li>
                        <a href="http://domain.com/about.html">About</a>
                    </li>
                    <li>
                        <a href="http://domain.com/Services.html">Services</a>
                    </li>
                    <li>
                        <a href="http://domain.com/index.php">Contact</a>
                    </li>

                    <li>
                        <a href="http://domain.com/Login/Sign-In.html">Login</a>
                    </li>

                    <li>
                        <a href="http://domain.com/Login/logout.php">Logout</a>
                    </li>

                    <li>
                        <a href="http://domain.com/PHP/Cart.php"><img src="images/Cart.gif" style="height: 20px; width:20px;"> Cart</a>


                    </li>

                </ul>
Sign up to request clarification or add additional context in comments.

Comments

0

There are some ways to fix this, one of them is:

Use $_SERVER["DOCUMENT_ROOT"] – We can use this variable to make all our includes relative to the server root directory, instead of the current working directory(script’s directory). Then we would use something like this for all our includes:

`<a href="<?php echo $_SERVER["DOCUMENT_ROOT"].'/path/to/about.html' ?>">about</a>`

Also you should check this post.

Comments

0

You could use the relative path to the root directory which is /file.ext

Example: <a href="/about.html">About</a>

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.