F
F
FBR2018-03-18 17:00:30
PHP
FBR, 2018-03-18 17:00:30

How to redirect all requests from a subdirectory or non-existent directory to index.php?

I need all requests to existing and non -existing directories/subdirectories and site files to be redirected to basic/api/index.php .
When I write , Hello World
test-site.com/basic/api //или api/index.php
opens in basic/api/index.php as I need. BUT when I enter the following links:

http://test-site.com/basic/api/src/    
http://test-site.com/basic/api/src/db/  
http://test-site.com/basic/api/src/db/dbconnect.php  
http://test-site.com/basic/api/src/app/  
http://test-site.com/basic/api/src/app/routes.php  
http://test-site.com/basic/api/src/bootstrap/  
http://test-site.com/basic/api/src/bootstrap/app.php  
http://test-site.com/basic/api/non-existent-folder/  //несуществующая директория
http://test-site.com/basic/api/non-existent-file.php //несуществующий файл

then the browser displays Page Not Found .
It is clear that the matter is in .htaccess, but damn it, I haven’t been able to configure it in this way for a week now, so I’m asking for help ...
I use this stuffing in .htaccess :
RewriteEngine On
RewriteBase /basic/ 
RewriteRule ^(.*)$ api/index.php

Project structure :
5aae6576e0ef2786542448.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Boris Korobkov, 2018-03-18
@BorisKorobkov

First, you need to remove all files, except for index.php and statics, outside http (a couple of levels higher).
Secondly, your regular ^(.*)/expression only works on paths that end in a slash. Figure out for yourself what needs to be fixed.

V
Viktor Taran, 2018-03-19
@shambler81

And also you have a regular season that allows you to do this
api/index.phpapi/index.phpapi/index.php
Which, as you understand, does not add health to it

RewriteCond %{REQUEST_FILENAME} !/api/index\.php
RewriteRule ^(.*)$ api/index.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question