lolka_bolka February 2016

.htaccess in subfolders

I read tons of topics about this here on SO, but for some reason it not works for me, and I am totally confused. I know, I mess up something, I just cant figure it what.

I have a site, and the index.php is calling the router, and show the content that I want.

I've created an admin' page, and I want the webserver to use the /admin/index.php for every request what is starting with /admin/

Here is what I try:

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 echoing some information from both index.php to see which handles my request.

If I am writing http://localhost it says Frontend.

When I try http://localhost/admin/ it says Frontend again.

If I am moving the admin' line below the first rule like this:

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

then http://localhost/admin/ says Admin what is actually good!

But if I try http://localhost/admin/users what is actually not there, because the admin's router should handle that, it says Frontend.

How should I set .htaccess to use /admin/index.php in all cases, where a http://localhost/admin/ in the URI?

Answers


anubhava February 2016

Have it like this:

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]

Post Status

Asked in February 2016
Viewed 2,436 times
Voted 13
Answered 1 times

Search




Leave an answer