Search code examples
phpapache.htaccessslashtrailing

Using htaccess to remove trailing slash


I have a url "www.example.com/abc/abc.php" If I change it to "www.example.com/abc/abc.php/asdasd", some kind of infinite loop starts and the server's memory peaks to 100%.

I have heard that there's some way by .htaccess by which I can redirect any "abc.php/asdasd" to "abc.php" only. Please help how, as I am not able to understand it from other examples mentioned on net.

NOTE : I dont want this "/" to be removed if it is put at the end of directories though.


Solution

  • I was able to achieve what I wanted by the following htaccess code :

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^(.*)\.php/(.*) $1.php [F]
    </IfModule>
    

    This may not be perfect, but gets the job done. Now anything after the text 'abc.php' results in a page-not-found. Works for cases like :

    www.website.com/abc.php/

    www.website.com/abc.php/asd

    www.website.com/abc.phpasd

    www.website.com/abc.php?

    etc.