File and directory named by the same PHP

I currently have these two parts on my site.

localhost/FTS/papersis a php file
localhost/FTS/papers/is a directory

What I want to do is make it so that on boot:

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

I want them all to go to a newspaper file.

Now he is accessing a directory, not a file that I do not need.

+3
source share
3 answers

Put this rule in your DOCUMENT_ROOT/.htaccessfile:

RewriteEngine On
RewriteBase /FTS/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/FTS/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
+1
source

I think this is rather confusing for PHP (as it is for me) when you are talking with a paper reference or a document.

, , documents_doc, , . ( ).

is_dir PHP, , :

var_dump(is_dir('a_file.txt'));
var_dump(is_dir('bogus_dir/abc'));

is_file:

var_dump(is_file('a_file.txt'));
var_dump(is_file('bogus_dir/abc'));
0

One thing you can do is put the htaccess file in a directory papersusing this rule:

RewriteEngine On
RewriteRule ^$ /FTS/papers.php [L]

And allow mod_dir to redirect /FTS/papersto /FTS/papers/.

0
source

All Articles