V
V
Viktor Zuev2017-08-03 10:44:19
PHP
Viktor Zuev, 2017-08-03 10:44:19

How to make a redirect of any level of nesting to the root of the site?

Good time!
I already googled my fingers into the blood, but I did not find an answer specifically on my topic.
There is a .htaccess file with the following content:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks -Indexes
    RewriteEngine On
    RewriteBase /
  RewriteCond %{REQUEST_URL} ^/.*
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?$1 [L,QSA]
</IfModule>

In the code, I parse the contents of $_SERVER['REQUEST_URI']. When accessing the root, respectively, the array is empty. Everything works out. If I address a specific controller with a line like
site.ru/controller/action,
then apache looks for a folder called controller and accordingly issues 404.
That is, the request is not redirected to index.php in the root of the site, but a folder with a specific name is searched and only in her requests go to index.php. Do I understand the current situation correctly and how to solve it, tell me, guru?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
A person from Kazakhstan, 2017-08-03
@LenovoId

https://stackoverflow.com/questions/1427721/how-to...

A
Andrey Nikolaev, 2017-08-03
@gromdron

How about the following code:

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?$1 [L]
  RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
</IfModule>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question