1

I have my URL like www.abc.com/some_folder1/some_folder2/page.php is there are any ways to hide "some_folder1 or 2" In URL while it is displaying on URL bar like :

www.abc.com/some_folder1/page.php

or

www.abc.com/some_folder2/page.php

(have to just hide "by keeping its functionalities unaffected")

Milan Chheda
  • 8,159
  • 3
  • 20
  • 35
  • 2
    This modification can be made using `.htaccess` or `web.config`. I don't think it can be made using jQuery – Mario Rawady Dec 28 '17 at 07:16
  • you may be able to do that only by caching that folder in localStorage and then redirect to the desired page, but that will still be visible for the first time to the user – stackoverflow Dec 28 '17 at 07:16
  • Thank you @MarioRawady. how can we do this using .htaccess ? – Deepak Bharadwaj Dec 28 '17 at 07:28
  • Are you looking to hide the path dynamically: `The folder name differs from scenario to scenario` or is it a predefined path that is not changeable? – Mario Rawady Dec 28 '17 at 07:35
  • No, it is not happening dynamically, It is a predefined path. I tried something like this in javascript, "window.location = window.location.href.replace('/some_folder1', ' ' );". but it is removing "some_folder1" and when I try to access the file I get, page not found. – Deepak Bharadwaj Dec 28 '17 at 07:46

1 Answers1

0

try this

 

console.log( window.location.href );  
window.history.replaceState( {} ,window.location.href.toString().replace( "/some_folder2","" ), window.location.href.toString() );
console.log( window.location.href );

This code will hide the text in URL in the browser address bar. It works for HTML5 enabled browsers.

Please take a look at this discussion for more details : history.replaceState() example?

Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
  • 1
    Thank you @RameshRajendran. but it will remove "some_folder2" and replaces with " ". and we will get, page not found error. I just want to hide it without affecting the functionalities. – Deepak Bharadwaj Dec 28 '17 at 07:53
  • Take a look at this discussion : https://stackoverflow.com/questions/25723654/replacestate-a-history-state-with-url-cannot-be-created-in-a-document-wit – Ramesh Rajendran Dec 28 '17 at 07:58