Using htaccess to remove trailing slash

291 views Asked by At

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.

2

There are 2 answers

1
soundswaste On BEST ANSWER

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.

2
Paul Dessert On

This would redirect one URL to another:

Redirect 301 /abc.php/adssd http://www.example.com/abc.php

However, this will only handle this one example. You should post your full .htaccess file so we can see what's really going on