How to not display "index.php" in the URL

I have a website - “rickandmorty.epizy.com”. All of my HTML files have an extension .php and I would like “index.php” not to be shown in the URL. Is there a way of doing this by creating a new .htaccess with some code in it in the .htdocs directory or do I have to get into more advanced stuff?

Just not add index.php to the URL? If no specific file is given for a directory, the web server will look for a index.php or index.html file.

E.g. visiting http://rickandmorty.epizy.com/ will show the same page as http://rickandmorty.epizy.com/index.php

Thank you very much. I knew that about index.html, for some reason I thought that it would be different for index.php.

By the way InfinityFree has the best admins.

@Admin said:
Just not add index.php to the URL? If no specific file is given for a directory, the web server will look for a index.php or index.html file.

E.g. visiting http://rickandmorty.epizy.com/ will show the same page as http://rickandmorty.epizy.com/index.php

Sorry, does this work with every page? For example if I have a “worldnews.php” removing php would it still work? I tried adding

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\\.]+)$ $1.php [NC,L]

to the .htacess inside .htdocs but it won’t do anything. It seemed like a better solution. Thanks in advance.

@perico said:

@Admin said:
Just not add index.php to the URL? If no specific file is given for a directory, the web server will look for a index.php or index.html file.

E.g. visiting http://rickandmorty.epizy.com/ will show the same page as http://rickandmorty.epizy.com/index.php

Sorry, does this work with every page? For example if I have a “worldnews.php” removing php would it still work? I tried adding

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\\.]+)$ $1.php [NC,L]

to the .htacess inside .htdocs but it won’t do anything. It seemed like a better solution. Thanks in advance.

The easiest way to have a file on <example.com>/worldnews is by creating a directory called worldnews and place an index.php file in it. A more scalable (but harder to implement) solution is to route everything to a central index.php file and route everything from there in your own code.

In my experience the .htaccess rules are hard to get right, so I try to rely on them as little as possible.