Forum

Hiding file extension in url

David
28 November 2017, 11:25
Hi Hugo,
I want to know whether we can hide file extension like .php , .html using url tool kit. Here is the whole idea lets say client type www.example.com/game in the browser so with this url should be converted to www.example.com/game.php and execute and finally on client browser it should only show www.example.com/game as url. Is it possible with url rewrite show me an example if it is possible.
Thanks
Hugo Leisink
28 November 2017, 11:27
The best way to do this, is by using a single index.php as the entry point for every request. Let that index.php do the routing (including and executing other PHP files) base on the request uri ($_SERVER["REQUEST_URI"]). You can use the following UrlToolkit to do the rewriting:
UrlToolkit {
ToolkitID = my_toolkit
RequestURI exists Return
Match .* Rewrite /index.php
}

Protect the other PHP files from being requested directly, by placing them outside the website root or by checking for a constant which was set in index.php. You could also prevent it via an UrlToolkit rule, to be placed before the last rule:
  Match \.php DenyAccess
David
28 November 2017, 13:23
Hugo the thing is client should not know that i am using php
Hugo Leisink
28 November 2017, 13:32
Why not? What's the risk of a client knowing you're using PHP? If you use the rewriting as described above, it hides the PHP extension. Also, don't forget to set expose_php to no in php.ini.
David
29 November 2017, 07:45
Thanks Hugo it is working
David
30 November 2017, 04:13
Hi Hugo
I used a set of regular expression that suits my need and it is hiding the file extensions and redirecting it perfectly.
Thanks a lot Hugo for the url tool kit it is really very simple to use and works perfectly.
This topic has been closed.