Is it possible that the php file in apache works without an extension?

I have a file

http://www.www.com/somefile.php

I would like to access the same file by going to

http://www.www.com/somefile

But I still need

http://www.www.com/directory

to open a file

http://www.www.com/directory/index.php

if in fact the directory is a directory.

This is a typical LAMP setup with Red Hat and Apache.

Is it possible? If so, how?

+3
source share
3 answers

The apache rewrite rule will do this for you. The only limitation is that you cannot have a file named "somefile.php" and a directory called "somefile" (although you still have directories.

Here's an example rule that supports multiple file names (just enter it in the .htaccess file).

RewriteEngine on
RewriteRule ^(somefile1|somefile2|somefile3) $1.php

/somefile1 /somefile 1.php,/somefile2 /somefile2.php /somefile 3 /somefile3.php.

+3

Apache ForceType.

+2

If you want to disable the need for file extensions throughout the URL on your site, you can also add the following to your .htaccess:

Options +MultiViews

This will allow consolidation of content . But if you want to map only specific files and / or URLs, use the SoapBox Answer .

0
source

Source: https://habr.com/ru/post/1731479/


All Articles