Search code examples
.htaccesshttp-redirectjoomla

.htaccess rule to remove index.php from the end of my urls


I have seen this asked before without an answer here: .htaccess rule to remove index.php at the end of urls

I'm having the same issue as the original poster. I have urls on my Joomla site that are showing up with index.php at the end. I want all urls ending with index.php to be redirected to the same page without the index.php at the end.

Example: www.mysite.com/forum/index.php should be redirected to www.mysite.com/forum

I have tried this code

    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]

But it redirects all url's with index.php at the end to my sites home page

Example www.mysite.com/forum/index.php ends up being redirected to www.mysite.com

Any help on this would be greatly appreciated!


Solution

  • You can use this rule as your very first rule:

    RewriteCond %{THE_REQUEST} !/admin/ [NC]
    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]