Ask HN: Do you remove your file extensions from URLs?

1 points by Random_Person ↗ HN
This is one of those things that I've thought about and battled with for the last few years of learning... should I be removing my extensions? I can't find a good answer. Does it hurt me that my users see that I'm using PHP?

5 comments

[ 4.4 ms ] story [ 22.1 ms ] thread
When you see a URL like news.ycombinator.com/item?id=foo, that isn't implemented by having a file called item.php. That is implemented by having URL routing handled by the application instead of by the filesystem.

I don't think there's any point removing extensions from images, CSS, javascript, etc., but I do think it's worth handling routing in your application instead of just doing it with a bunch of PHP files.

Just curious why you would choose to write your own route handler.

I use them (via Laravel) on work projects and I hate them. I hate that I have to look at a routes file or controller to find out what is pointed where in my file. I have all my route-handling stuff for each page, at the top of each page so I don't have to go look elsewhere for that info. Is this wrong?

You wouldn't write your own route handler, you'd just use a framework.

It needn't be complex. I mostly use Mojolicious, where it's as simple as:

get '/' => sub { ... };

get '/item' => sub { ... };

etc.

>I use them (via Laravel) on work projects and I hate them. I hate that I have to look at a routes file or controller to find out what is pointed where in my file.

Laravel's router is one of the best out there. It makes default parameters a breeze. If you ever get into API development you have no option but to become an expert on routing.

>Is this wrong?

You should read more documentation and tutorials and try out some other frameworks to see how they handle routing! You'll realize that Laravel's routing is extremely easy to use compared to frameworks. Automatic routing by naming convention like CakePHP and Rails is a recipe for an unmaintainable mess when you're forced to then structure your controllers based on the request type and name them whatever you want your endpoint to be.