tags:

views:

137

answers:

4

I know there are a lot of tricks for doing links, for example <a href="?query=string"> will link to the current page after appending the query string. Is there a way to link back to the current page, after removing the query string without just typing the file name?

Example, at the page foo.php?q=3, I want to link to foo.php. Is there a shortcut-type way to do this? The file will be renamed several times, so I don't want to type a bunch of links and then have to edit them later.

Edit: Even though these are PHP files, I'm trying to avoid a server-side solution for this particular problem.

A: 

Dont forget about anchors

<a href="foo.php#">xxxx</a>
BozoJoe
+3  A: 
href="?"

Not exactly what you are after - there's still a question mark at the end - but functionally equivalent.

Alex Barrett
Thanks, good call.
Shadow
A: 

Are you wanting a client-side equivalent to $_SERVER['PHP_SELF']? Something that will always link to the file with no extra stuff after the extension?

I'm not sure if this works in all browsers, but it works great in Firefox 3.5:

<a href="">Foo</a>
Anthony
It doesn't clear the existing query string.
Alex Barrett
A: 

You can link to the current page you're on with:

<a href="#">blah</a>
Tim
This does not perform a new request to the server in all browsers.
Alex Barrett