1

This is for bit of a knowledge gainer for me really, everyday is school day and I like to know what is possible, and not try to have a go at something is impossible.

I have with help here (.htaccess to hide 2 folder paths) shortened the full path so people access the website don't know the full directory.

My problem is now that I would like the short URL if typed in not too resolve, but only can be navigated through, I want the URL just be purely for display I suppose, and if it was to be entered it wouldn't work. Is this possible?

Community
  • 1
  • 1
ManWithNoName
  • 67
  • 2
  • 13
  • So you want something like http://shorten.er/XXXXX to go to http://example.com/example bit still show http://shorten.er/XXXXX in the address bar? – Nick Taylor Apr 03 '16 at 18:40
  • No I want to achieve something that if the user types in example/pictures/pictureone.php (which htaccess shortens the following example/media/pictures/pictureone.php) to not work when it is typed in. – ManWithNoName Apr 03 '16 at 18:46

1 Answers1

0

You can't do this with .htaccess rewrite rules — if the URL works in a link, then it also works if typed in.

(OK, technically you could make your rewrite rules conditional on the presence of an appropriate HTTP Referer (sic) header, but that's not something you really should rely on.)

What you could do is fake the URL shown in the browser's address bar using the JavaScript History API, like this:

history.replaceState({}, "", "/whatever")

(Try running that in your browser's JS console!)

Of course, that's a purely cosmetic change; you'd still need to use the real URL of the page in your links, and it would be trivial for anyone with a basic understanding of how web browsers work to figure out the real URL. It also has the annoying side effect that reloading the page will cause the browser to try to load the fake URL, likely breaking the page. But that's pretty much inevitable; there's effectively no difference between reloading a page and typing its URL into the address bar. But if you're OK with all that, it could be one way to go.

Honestly, though, I suspect that what you really should do is to stop trying to do this, and instead take a step back and try to find an alternative solution to your real problem, whatever it may be.

Community
  • 1
  • 1
Ilmari Karonen
  • 49,047
  • 9
  • 93
  • 153