My site uses both PHP and the JS AJAX so I'm fairly familiar with them both, and I don't want a solution that includes them. I have this page structure where all my users stay on just one landing php page, which then fetches the right content depending on the URL's p variable.
http://www.example.com/?p=about
http://www.example.com/?p=aMap-anothermap-evenAnothermap-lastelyTheFile
This page structure works great for me except that I don't know the right way to make a link that just removes the whole ?p=home
. Because I want my home/start page to be variable free. I want it to be
http://www.example.com/
rather than
http://www.example.com/?p=home
Now I could just make the link
http://www.example.com/?
And then just remove the ?
with the JS pushState()
, but that would look pretty silly and would only work for JS users.
Let's say i would want to the do the above example with just the ?
then I could create a link like this.
<a href="?">Link</a>
<script src="SomeCoolPushStateScript"></script>
And I know from experience that this doesn't even work:
<a href="">Link</a>
So here comes the question: How do I remove the ?variable=something
part of an URL when using an HTML href
?
The path ./
should do the trick.
<a href="./">Link</a>
If you want to preserve the main script name, like index.php
, you will have to include that name.
<a href="index.php">Link</a>
Alternately, you could dynamically generate domain-relative or absolute URL's with PHP.