Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File and Directory Named the Same PHP

I currently have these two pieces to my website.

localhost/FTS/papers - which is a php file
localhost/FTS/papers/ - which is a directory

What I am wanting to do is make it so that when I load:

localhost/FTS/papers -or-
localhost/FTS/papers/ -or-
localhost/FTS/papers.php

I want them all to go to the papers file.

Right now it is accessing the directory instead of the file which is not what I want.

like image 675
FreeTheStudents Avatar asked Mar 08 '26 12:03

FreeTheStudents


1 Answers

Place this rule in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On
RewriteBase /FTS/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/FTS/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
like image 139
anubhava Avatar answered Mar 10 '26 02:03

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!