skip to Main Content

I currently have a .htccess that redirects to 404.html when a error 404 is received. Now my problem is how to remove index.php in a url. Example http://example.com/test/index.php. I want it to be http://example.com/test.

RewriteEngine on
RewriteCond % {REQUEST_FILENAME} !-f
RewriteCond % {REQUEST_FILENAME} !-d
RewriteRule ^ 404.html
ErrorDocument 404 /404.html

I am using xampp apache.

2

Answers


  1. This should redirect like you are expecting from the test I did
    RewriteRule ^(.*)/index.php$ $1 [L,QSA]

    Here is where you can see the test
    https://htaccess.madewithlove.be?share=78711e7e-4d95-5116-8c28-83d0362d3632

    Login or Signup to reply.
  2. To allow the user to execute “/test/index.php” whenever they access “/test/”, probably the easiest way is using DirectoryIndex. Just append this line to your .htaccess file:

    DirectoryIndex index.php
    

    This will allow the execution of http://example.com/test/index.php whenever the user accesses http://example.com/test/ – and for any other URL.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search