0

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).

Community
  • 1
  • 1
Matt Aikens
  • 71
  • 2
  • 11

1 Answers1

0
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.

stormdrain
  • 7,915
  • 4
  • 37
  • 76
  • Thanks, but that still doesn't work. It is still falling back on the index.php rule. – Matt Aikens Mar 10 '14 at 18:44
  • Ah, I forgot about the rewrite base. Edited. – stormdrain Mar 10 '14 at 19:36
  • Nope, no dice. And, I thought the string in question was taken from the RewriteBase on? I'm just curious as to why ^admin$ doesn't at least work. I mean.. it's so simple. start, admin, end. – Matt Aikens Mar 10 '14 at 20:23
  • I'm working with an online tester too (http://htaccess.madewithlove.be) which isn't 100% accurate. I thought the same thing, but it wasn't working without accounting for the base. Try removing the trailing slash from the rewrite base: `/dev` – stormdrain Mar 11 '14 at 13:10
  • Nope, still doesn't work. Are you actually getting it working on that online tester? – Matt Aikens Mar 11 '14 at 14:00
  • Yeah it works there: http://i.imgur.com/lfWULCX.png I just noticed something though, you don't have `dev` in any of your example URL's. Please update your questions with as many details as you can (including paths, URLS, and full relevant folder structure). – stormdrain Mar 11 '14 at 14:35
  • Did you figure out what the problem was? – stormdrain Mar 12 '14 at 13:20
  • Well I thought it was htaccess since the tester kept coming up negative, but that was a red herring. Once I settled on a working rewrite rule, it turned out the problem was in my preController hook with some stuff I was doing based on the Routing class. I ended up using your rule in lieu of two less efficient ones, so thank you!| I didn't bother posting my solution because it won't be applicable to virtually anyone. – Matt Aikens Mar 13 '14 at 15:54
  • Ah, damn herrings! Good to hear you got it figured out :) – stormdrain Mar 13 '14 at 16:39