0

i want to remove index.php from home page url ex: https://url.com/index.php change into https://url.com/

and remove .php extension from other files

ex: https://url.com/contact.php

change into https://url.com/contact

abhishek
  • 1
  • 1
  • Does this answer your question? [Remove .php extension with .htaccess](https://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess) – Reece Sep 22 '20 at 08:31

2 Answers2

1

You can append this to your .htaccess file to make all PHP files have their extension removed. You're required to have mod_rewrite enabled.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

As similarly seen here, adjusted to PHP.

Reece
  • 574
  • 3
  • 10
0

By default, Apache will automatically look for index.php if you enter a directory rather than a resource. So in that case, just don't type the index.php part. If you want to change it from the filename index to something else, you can modify the DirecctoryIndex in your .htaccess file.

In the case of https://url.com/contact, you can create a directory called contact and put your index.php file in that.

If you're passing arguments via the url and you don't want the user to see them, you can use javascript to change what is shown in the address bar.

PoorlyWrittenCode
  • 1,003
  • 1
  • 7
  • 10