Search code examples
phpapache.htaccessmod-rewritehttp-redirect

Htaccess code redirects to XAMPP index page


I am trying to write htaccess codes which redirect all URLs apart from directly linked files (e.g images & css files) to my index.php file for processing

http://localhost/testsite/login

redirects to

http://localhost/testsite/index.php?cmd=login

But the htaccess code instead redirects me to the XAMPP homepage. This is my htaccess code

DirectoryIndex index.php

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?cmd=$1  [QSA,NC,L]

What am I doing wrong?


Solution

  • Remove / from target and use proper RewriteBase:

    DirectoryIndex index.php
    RewriteEngine on
    RewriteBase /testsite/
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ index.php?cmd=$1  [QSA,L]
    

    /index.php will route it to site root index.php instead of index.php in current directory.