2

I'm trying to remove index.php from my subfolder url. so if anyone access www.mysite.com/sub-folder/index.php i want the url to redirect to www.mysite.com/sub-folder/. I've added the following htaccess file in sub-folder, but its not working.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sub-folder/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sub-folder/index.php [L]
</IfModule>

Can anyone help me with this? Thanks

1 Answer 1

4

You can use this .htaccess in /subfolder/.htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sub-folder/

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

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
Sign up to request clarification or add additional context in comments.

4 Comments

its work, but if file does not exist in folder its not return to 404 page instead return index page content i mean for example 'page.php' file is not in 'subfolder' but if i call 'www.mysite.com/subfolder/page.php' this file is getting the content of index.php from 'subfolder'
404 won't be returned because you're sending every non-file and non-directory to index.php
Hi, how to make mysite.com/8to10differentsubfolders/index.php OR mysite.com/8to10differentsubfolders/ to mysite.com/8to10differentsubfolders.php through htaccess? Note: all subfolder have index.php file only inside it.
Please post a new question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.