I would say its a wrong logic to do it on the client side.
In fact you cant(should'nt) edit the url for cosmetic purposes on the client side.
You can do this with an htaccess mod on the Server Side (ASSUMING YOU HAVE AN APACHE SERVER, SINCE YOU ARE EDITING A PHP PAGE IN THE URL).
Add the below line to your htaccess file in the server directory(where your page is situated)
for example in www.example.com/test,
put the below line in the test directory ('.htaccess') file
DirectoryIndex index.php index.html site-down.php
so when you go to www.example.com/test you get the index.php page.
Don't edit URL's on client side ! This is not a good practice as well as not good for SEO.
Even if you have some different server like nGinx / ISIS etc..
Do it properly on the server side where it should be done !
I can undertand if it was for removing an "#id" etc.. from the url
for which your existing code is appropriate. But editing target pages is a no no !
I recommend you to read an existing stackOverflow page..
Apache friendly urls
to create true user+seo friendly url's.