Hi Everyone, I am having a bit of a mare trying to get my htaccess file working the way I would like it too.

I am trying to redirect the index.php
from websitename/directory/index.php
to websitename/directory/

I have tried the following rewrites but nothing seems to be working, Hope someone can point out what or where I am going wrong.
Thanks in advance.

Here is what I have in my htaccess file.

#   Enable Rewriting
#   RewriteEngine on
#   Symlinks
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /shop-product.php?pid=$1 [QSA,L]

#Force Root Redirect
#RewriteEngine On
#RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
#RewriteRule ^index\.php$ / [L,R=301]

#RewriteEngine On
#RewriteRule ^index\.html$ / [R=301,L]
#RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]

#force Root index redirect
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

First your htaccess rules are written to NOT redirect index.php

The rules are: If the request filename (index.php) is not a file and is not a directory then redirect to index.php. Well obviously index.php is a file, so your conditions don't apply.

Also you have 2 things to worry about, first is redirecting /index.php to / and then handling the / with index.php

I would do something like this in the .htaccess

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_URI} /index\.php [NC]
RewriteRule ^ / [NE,L,R]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php/$1 [L]
</IfModule>

Also, very important, in the Apache HTTP server configuration, make sure AllowOverride All is set for the website document root and make sure the Apache mod_rewrite module is loaded in the main config.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.