0

I have the following .htaccess file, which should rewrite all non-existent files/folder to index.php. Could someone suggest a way to debug why this wouldn't work? When I go to a non-existent folder I receive a 404 not-found page.

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.*$ ./index.php

when I visit domain.com/ the index.php file shows properly

the .htaccess file is in the same directory as index.php

d-_-b
  • 21,536
  • 40
  • 150
  • 256

3 Answers3

1

First of all, you must ensure that mod_rewrite is enabled and working, otherwise you will keep getting 500 Internal Server Error.

You can check that, simply by using apache_get_modules(). For example,

// File : test.php
<?php

if (in_array('mod_rewrite', apache_get_modules()){
   echo 'mod_rewrite is installed and ready to be used';
} else {
   echo 'mod_rewrite is not installed';
}

If it prints that mod_rewrite is installed and ready to be used, then you can use something like this,

    RewriteEngine On

    # I guess you're missing RewriteBase
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]
Yang
  • 8,580
  • 8
  • 33
  • 58
0

Can you try this code:

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^ /index.php [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

Did you try this

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^.*$ /index.php [L]

EDIT here is post you may be useful Tips for debugging .htaccess rewrite rules

Community
  • 1
  • 1
Oleksandr IY
  • 2,783
  • 6
  • 32
  • 53