简体   繁体   中英

CodeIgniter Multi Application htaccess issue

Before you tell me to go to CodeIgniter multi-application .htaccess problem , hear me out.

The reason I say that is because my problem seems to be nearly the exact same as this posters. My directory structure is:

application/
   admin/
   app/
..
.htaccess
admin.php
index.php

The htaccess rules are:

RewriteEngine On
RewriteBase /dev/

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin$ admin\.php [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin\/(.*)$ admin\.php/$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index\.php/$1 [L,QSA]

Essentially what I need is:

type in example.com/admin - the url keeps the admin folder, and redirect the user to admin.php

type in example.com/admin/controller/method - same as above

type in example.com/anything_else - the user gets directed to the app instead of admin (index.php)

In testing the person in the aforementioned post's htaccess, which mine are essentially copied from, in an online tester, the two rules involving URIs with 'admin' in it are not passed for some reason. I can only get admin (not ^admin$) to work as a pattern (according to the tester).

RewriteRule ^dev/admin(\/?) admin.php? [L,QSA]

Should do it for you. This will account for /admin , /admin/ and /admin/whatever/here . But for the latter, be aware that since you have QSA on it will append it to the destination URL like so: /admin.php?whatever/here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM