Dipak
Dipak

Reputation: 939

Redirect all subfolder's home to index using 301

My website structure is like

Main (Root directory)

index.php
home.php

Sub-folder

index.php
home.php

There are many sub-folder under root directory.

I am able to redirect main root home page to index by using following code

Redirect 301 /home /
Redirect 301 /home.php /

But, I want to redirect all sub-folder's home to it's own index page. How can I do ? Any suggestion ?

Upvotes: 1

Views: 574

Answers (2)

anubhava
anubhava

Reputation: 786339

You can use this code in your DOCUMENT_ROOT/.htaccess file:

DirectoryIndex index.php
RewriteEngine On
RewriteBase /

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

This routes /news/home to /news/index.php OR /home to /index.php

Upvotes: 1

RAQnJAQ
RAQnJAQ

Reputation: 1

If you are running on a server, use the 'dot' to start at the root.

./home/

Upvotes: 0

Related Questions