W
W
ward_ua2021-06-08 07:29:24
PHP
ward_ua, 2021-06-08 07:29:24

How to process all requests in one file on Apache?

I decided to write a small PHP application similar to how I did it on nodeJS. I chose MVC as a template, undertook to write a controller, but I ran into the fact that I can’t access the controller.php file with each request, since Apache (like other PHP-enabled servers) requests the file specified in the request path. I found on the Internet a seemingly solution to this problem using the .htaccess file:

RewriteEngine On  
  
RewriteCond %{SCRIPT_FILENAME} !-d  
RewriteCond %{SCRIPT_FILENAME} !-f  

RewriteRule ^(.*)$ ./index.php?route=$1


But the problem with this configuration is that you can't get the get-/post-request data for the controller to process. Please help edit .htaccess so that the controller receives the request body. Thanks in advance for your replies.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
swaro, 2021-06-08
@ward_ua

RewriteEngine On
RewriteRule ^.*$ index.php

Get URL:
$url = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question