Remove the ".php" extension when using S3 / EC2

I installed the application and downloaded the files using the elastic beanstalk. Files are saved in the S3 bucket with the EC2 instance running.

The problem is that I can only access site files when I manually add the .php extension.

I built the application using the .htaccess file to remove the file extension, then my redirects and functions will use the files without ending, for example. "/ index" instead of "/index.php".

Because .htaccess is not an option using S3 buckets, is there a simple alternative way to remove file extensions? (therefore, the files "/index.php" are considered "/ index", then all functions / redirects work fine).

+6
source share
1 answer

You can use mod_rewrite to achieve this. For example, this rule redirects to the index when the file is not found in the current directory. For example, if you are accessing / users, and since it is not a file. The request will be passed to index.php. In index.php, you can process the URL using $ _SERVER [REQUEST_URI] and request the correct file.

<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L] </IfModule> 
0
source

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


All Articles