Camberra CacaitA
Camberra CacaitA

Reputation: 21

Redirect subfolder index.php to subfolder root

I have the following url I want redirect using the .htaccess file in root with Mod Rewrite. I have searched and found good examples for the index file in root, but not in subfolder. This is what I have and what I need. Thank you in advance for your help.

/folder1/index.php /folder1/index.php/ to http://www.example.com/folder1/

/folder2/index.php /folder2/index.php/ to http://www.example.com/folder2/

I was asked for only 2 hyperlinks so I removed part of the link on the examples above. I appreciate the shorter way because I have many folders.

Upvotes: 2

Views: 1040

Answers (2)

Amit Verma
Amit Verma

Reputation: 41219

To redirect /folder/index.php to /folder ,You can use :

RewriteEngine on


RewriteRule ^([^/]+)/index\.php$ /$1/ [NC,L,R]

This will redirect :

  • /anyfolder/index.php

to

  • /anyfolder/

Upvotes: 0

Codeguy007
Codeguy007

Reputation: 891

Try this in your .htaccess file.

RewriteEngine On

Rewrite  ^/folder1/index.php$ /folder1/ [L]
<Directory folder1>
   DirectoryIndex index.php
</Directory>

Of course the index can be what every you want like newindex.php.

Upvotes: 0

Related Questions