Hiding PHP pages in URL Bar

Hi all,
How do I hide whether I’m using PHP in the URL so that it only shows paths and not the actual pages. Below is the sample HTML nav:

<ul>
    <li><a href="http://localhost/~me/mysite/home/index.php">Home</a></li>
    <li><a href="http://localhost/~me/mysite/about/index.php">About</a></li>
    <li><a href="http://localhost/~me/mysite/contact/index.php">Contact</a></li>
</ul>

In the URL bar I don’t want it to apear as:

http://localhost/~me/mysite/home/index.php

But

http://localhost/~me/mysite/home/

Instead. In other words without showing that index.php page.

How do I do that with PHP or do I do that with PHP? I’m having problem if I click the link again second time the way I’ve done it in HTML.

Thanks

If you are using Apache (I’m assuming you are), search for DirectoryIndex directive and if it doesn’t exist, add index.php in the list.

That way, when someone requests a URL looking like /~me/mysite/home/, Apache will look to serve index.php first.

That’s the easy way out, it works as you can guess - for a file that’s being called as default once a directory is requested without file at the end of the URL.
There’s also more complex solution called mod_rewrite that goes together with rewrite rules and pretty nasty regexps. If the first solution isn’t the one you need, say so and I’ll try to provide sufficient info about mod_rewrite so you can use it.

I just want to make a correction firstly. The HTML code should look like this:

<ul>
    <li><a href="http://localhost/~me/mysite/home/">Home</a</li>
    <li><a href="http://localhost/~me/mysite/about/">About</a></li>
    <li><a href="http://localhost/~me/mysite/contact/">Contact</a></li>
</ul>

and in the URL bar it should appear as:

http://localhost/~me/mysite/home/
http://localhost/~me/mysite/about/
http://localhost/~me/mysite/contact/

This way the the server looks for the index.php in each folder. But as I said clicking on the link the second time is causing errors (just wanted to clarify myself).

NOW BACK TO YOU:

Yes I have apache running on mac OS X… where can I look/search for directoryIndex? Sorry I’m so dumb…

Check out this SitePoint guide to mod_rewrite. :slight_smile: