How can I remove file extension from a website address?

Viewed 111869

I am designing a website. I want my website address to look like the following image:

File name extensions like (PHP/JSP) are hidden

I don't want my website to look like http://something.example/profile.php. I want the .php extension to be removed in the address bar when someone opens my website. In other words, I want my website to be like: http://something.example/profile

As a second example, you can look at the Stack Overflow website address itself.

How can I get this done?

11 Answers

For those who are still looking for a simple answer to this; You can remove your file extension by using .htaccessbut this solution is just saving the day maybe even not. Because when user copies the URL from address bar or tries to reload or even coming back from history, your standart Apache Router will not be able to realize what are you looking for and throw you a 404 Error. You need a dedicated Router for this purpose to make your app understand what does the URL actually means by saying something Server and File System has no idea about.

I leave here my solution for this. This is tested and used many times for my clients and for my projects too. It supports multi language and language detection too. Read Readme file is recommended. It also provides you a good structure to have a tidy project with differenciated language files (you can even have different designs for each language) and separated css,js and phpfiles even more like images or whatever you have.

Cr8Router - Simple PHP Router

Related