Welcome Guest, Not a member yet? Register   Sign In
htaccess and multiple applications
#1

[eluser]Unknown[/eluser]
Hello all. I am exited to try CI but am having difficulty right out of the gate and am hoping that you can help me. What I want is to run two applications while hiding the index pages and suspect the problem lies with htaccess.

This is my current DocumentRoot directory structure:
[pre]
/
/subdir
/subdir/system/applications/backend
/subdir/system/applications/frontend
/subdir/backend_index.php
/subdir/frontend_index.php
[/pre]
This is how I want the URLs to function:
[pre]
http://192.168.1.76/subdir/admin/ -> backend
http://192.168.1.76/subdir/ -> frontend
[/pre]

Out of frustration I blew everything away (including all previous .htaccess attempts) and threw in a stock install in the above setup. The only things that have been changed are the app directory and the following changes made to the index and config pages:
[pre]
$application_folder = "application/frontend"; //frontend_index.php
$application_folder = "application/backend"; //(backend_index.php
$config['index_page'] = ""; //both config files
$config['base_url'] = "http://192.168.1.76/subdir/"; //both config files
[/pre]
I have read through the forums, wiki and Google and have spent a good amount of time playing with htaccess, but I simply can not figure it out. Can anyone throw a dog a bone?

If it matters, I am running Apache 2, PHP 5.2.5 and this is a virtual host. Since this is a private server I can change anything I need to. Thanks, I really appreciate this.
#2

[eluser]ontguy[/eluser]
Please post the .htaccess file.

Is it one application with a frontend and backend?

I think you could use subfolders with one index.php file and eventually put some authentication on any controller in your admin folder; http://ellislab.com/codeigniter/user-gui...subfolders
#3

[eluser]Unknown[/eluser]
[quote author="ontguy" date="1203560394"]Please post the .htaccess file.

Is it one application with a frontend and backend?

I think you could use subfolders with one index.php file and eventually put some authentication on any controller in your admin folder; http://ellislab.com/codeigniter/user-gui...subfolders[/quote]

Thanks for the reply. I don't have an .htaccess file. Right now I have nothing but a stock CI install with the application folder removed from system, and two applications (frontend and backend) in that folder. Actually, they aren't really applications since there isn't anything in the folders yet, just the skeleton.

My idea was to have two applications, one be a public front end that is accessed through /journals/ and a private, protected backend that is accessed through /journals/admin/.

Edit: Actually, that subfolder suggestion of yours might do the trick. I didn't think about that when I originally read over the documentation. I'd still be interested in how to split up multiple applications though, if anyone knows the answer to my original question.
#4

[eluser]ontguy[/eluser]
NP. According to the doc, if you're not using mod rewrite $config['index_page'] should have a value.

Another point about the subfolders, you could routing give the URLs the path you have in mind:

$route['admin'] = "backend/user";
http://yourdomain/admin/
would go to
...controllers/backend/user.php

Also what's outline on this page may help to do what you have in mind; http://ellislab.com/codeigniter/user-gui..._apps.html.
It may not though, you'd have to manually switch between applications.
#5

[eluser]trice22[/eluser]
Hello,

did you find solution for your problem?—I'm fighting with a very similar situation and can't find a solution.

Folderstructure:
Code:
/ci_test/.htaccess
/ci_test/application
/ci_test/application/frontend/
/ci_test/application/backend/
/ci_test/backend_index.php
/ci_test/frontend_index.php

In frontend_index.php:
Code:
$application_folder = "application/frontend";

In backend_index.php:
Code:
$application_folder = "application/backend";

b]In /application/frontend/config/config.php and
/application/backend/config/config.ph:[/b]
$config['index_page'] = "";[/code]

In .htaccess Only for the frontend for now—I figured, once I get this working…
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /frontend_index.php/$1 [L]

Now if I try "http://localhost/ci_test/" I'll get:
Quote:The requested URL /frontend_index.php/ was not found on this server.

I'd bet that's something small, but it seems that I can't find it.

If I leave the .htaccess-file away and try "http://localhost/ci_test/frontend_index.php" it will work.

Anyone some advice?

Thanks a lot in advance,
—trice
#6

[eluser]Pascal Kriete[/eluser]
The problem is in the last line of your htaccess file. You tell it to look for frontend_index.php in the server root. It should be:
Code:
RewriteEngine on
RewriteCond $1 !^(frontend_index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /ci_test/frontend_index.php/$1 [L]

Also notice that I changed the RewriteCond to exclude frontend_index instead of index.
#7

[eluser]trice22[/eluser]
Thanks man! That did the trick.

May I bother you with two more questions?

—For some reasons my app now can't access the css-files anymore, even though the path is correct (and even hasn't changed).
Is that a side-effect of the .htaccess?
They're located here:

Code:
/ci_test/assets/ <--- CSS,  JS,  etc.
/ci_test/application
/ci_test/application/frontend/
...
and linked via base_url().

—Could you give me a hint, how to write the .htaccess for the the backend, too?
Let's say all requests like this
Code:
http://localhost/ci_test/cms/
should point to the backend_index.php ?
Or should I just set up a route in the frontend-app.?

Thanks, I really appreciate your help.
—trice
#8

[eluser]trice22[/eluser]
Found the answer for my first question (pretty much by accident Big Grin )

In .htaccess
Code:
RewriteEngine on
RewriteCond $1 !^(frontend_index\.php|images|robots\.txt)
RewriteCond %{REQUEST_URI} !^/ci_test/assets
RewriteRule ^(.*)$ /ci_test/frontend_index.php/$1 [L]

—trice
#9

[eluser]Pascal Kriete[/eluser]
You're starting to mix things now, you can just add the asset folder to the allowed files/folders:
Code:
RewriteCond $1 !^(frontend_index\.php|images|assets|robots\.txt
If you have your images in your assets folder, then you can probably remove that. Also if you don't have a robots.txt file you can get rid of that, it's not needed.

I've never done this for two applications, but something like this should do it (using the cms example here):
Code:
RewriteRule ^cms$ backend_index.php [L]
RewriteRule ^cms/(.*)$ backend_index.php/$1 [L]

You have to add that in front of the other rules, so your final .htaccess file looks something like this:
Code:
RewriteEngine on

#Backend directories
RewriteRule ^cms$ backend_index.php [L]
RewriteRule ^cms/(.*)$ backend_index.php/$1 [L]

#Everything else
RewriteCond $1 !^(frontend_index\.php|assets)
RewriteRule ^(.*)$ /ci_test/frontend_index.php/$1 [L]
#10

[eluser]trice22[/eluser]
Thanks again for the effort, you're making here.
I'm getting a 404 atm. but I count that actually to be good sign so far. I'll look into it tomorrow or so and let you know…

Cheers,
—trice




Theme © iAndrew 2016 - Forum software by © MyBB