.htaccess in subfolders

I read a ton of topics about it here on SO, but for some reason this doesn't work for me, and I'm completely confused. I know, I ruined something, I just can’t understand it.

I have a website, and it index.phpcalls the router and shows the content that I want.

I have created an admin page and I want the web server to use /admin/index.phpfor every request, starting with/admin/

Here is what I am trying:

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^admin/(.*)$ admin/index.php?action=$2   [L,NC]
RewriteRule ^(.*)$ index.php?action=$1 [L]

I repeat some information from index.phpto see which one is processing my request.

If I write http://localhost, he speaks Frontend.

When I try http://localhost/admin/, he speaks again Frontend.

If I move the admin line below the first rule, for example:

RewriteRule ^(.*)$ index.php?action=$1 [L]
RewriteRule ^admin/(.*)$ admin/index.php?action=$2   [L,NC]

http://localhost/admin/ Admin, !

http://localhost/admin/users , , - , Frontend.

.htaccess /admin/index.php , a http://localhost/admin/ URI?

+4
1

:

RewriteEngine On

# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^admin/(.*)$ admin/index.php?action=$1 [L,NC,QSA]

RewriteRule ^(.*)$ index.php?action=$1 [L,QSA]
+4

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


All Articles