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

[eluser]Rein Van Oyen[/eluser]
Hi there,


I'm using 2 applications while using 1 CodeIgniter system. I have everything set up and working. Except for my mod_rewriting. Both of my files are in the root, 1 named index.php the other 1 is called admin.php.

Using following rules in my .htaccess removes the index.php in my url.

Code:
RewriteCond $1 !^(index\.php|admin\.php|admin|_images|_css|_js|_uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

But when I add the following rules, I can't seem to point "admin" to "admin.php". It gives a CodeIgniter 404.

Code:
RewriteRule ^/admin$ /admin.php/$1 [L]
RewriteRule ^/admin/$ /admin.php/$1 [L]

Could anyone point me in the right direction? It would be highly appreciated.

Thanks in Advice,
Rein
#2

[eluser]ChrisMiller[/eluser]
You can try this Rein and see if this works for you, I am a little rusty with my .htaccess but it should work as its code taken from a production website of mine.

Code:
RewriteEngine On
Options Indexes FollowSymlinks Multiviews
RewriteBase /

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

Basically it checks to see if a file or folder actually exists such as admin.php which if it does then it handles the request and if it doesn't then it bumps it to CI.

- OR -

Code:
RewriteEngine On
Options Indexes FollowSymlinks Multiviews
RewriteBase /

RewriteCond %{REQUEST_URI} !admin/
RewriteRule ^(.*)$ /admin.php/$1 [L]

RewriteCond $1 !^(index\.php|admin\.php|admin|_images|_css|_js|_uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Your .htaccess fixed to a degree with some modifications I am not positive if this will work It looks correct in theory; let me know and I will gladly help sort it out. I have been at the other end many of times completely lost especially with htaccess as I mainly work with php/mysql

- Enjoy
#3

[eluser]Rein Van Oyen[/eluser]
Dear ChrisMiller,

first of all; thank you very much for your reply!

The first rules work, but are not exactly what I'm looking for. It would still need the admin.php in the url and the main goal for me is to remove that. I also like to specify which files/dirs can be accessed instead of having the system searching for files/dirs that exist.

So, the second code looks better to me, but despite that, it doesn't work. I'm getting a 500 Internal Server Error on every url.

Anyone has ideas? This looks like something that should be relatively easy, but I guess I'm not much of a regular expression/htaccess guy. Sad


Greetings,
Rein
#4

[eluser]ChrisMiller[/eluser]
Sorry About that, I fixed the code and tested on my own server so It should be good. It was a missing $ that caused it.

Code:
RewriteEngine On
Options Indexes FollowSymlinks Multiviews
RewriteBase /

RewriteCond %{REQUEST_URI} !admin/$
RewriteRule ^(.*)$ /admin.php/$1 [L]

RewriteCond $1 !^(index\.php|admin\.php|public|media)
RewriteRule ^(.*)$ /index.php/$1 [L]
#5

[eluser]Rein Van Oyen[/eluser]
Thanks again ChrisMiller! I appreciate all your help.

I fully understand the code and that's indeed what I need. But after pasting it in my .htaccess. Every http request to the domain still gives a 500 internal server. When I comment out following lines, the 500 error is gone. I need those lines, tho.

Code:
RewriteCond %{REQUEST_URI} !admin/$
RewriteRule ^(.*)$ /admin.php/$1 [L]

I don't have any clue on why these don't work...My error log says something about too much requests. Am I creating an infinite loop here? Is there any way that this could be because of my CI configuration?

Thanks in advice,
Rein
#6

[eluser]Rein Van Oyen[/eluser]
Is there anyone who knows the issue? I'm getting a headache from this.

The error in my error log;

[Tue Feb 15 13:18:23 2011] [error] [client 178.117.99.182] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.


Sorry for bumping.

Rein
#7

[eluser]WanWizard[/eluser]
This is indeed an infinitive loop, which mod_rewrite terminates after the limit has been reached.
Do what is suggested, create a rewrite log and bump the log level to 9, to see exactly what is going on.

And make it more clear what you are trying to achieve.

If you have two apps in the same root, you need to tell mod_rewrite exactly what needs to be rewritten. If both are using index.php hiding (or admin.php in this case), that might prove to be a challenge...
#8

[eluser]Rein Van Oyen[/eluser]
Thanks for the reply WanWizard!

I'll try to make myself more clear. What I have is 2 files in my root, one of the is named index.php and the other one is named admin.php. Each one of these is linked to the correct application folder.

Everything works without the .htaccess. For example when browsing to http://www.mydomain.com/index.php/controller/method/ or http://www.mydomain.com/admin.php/controller/method/ it loads the correct application, controller and method.

What I want to achieve is to remove the index.php from the first url and replace the admin.php with /admin/.

Also; I'm not allowed to create a rewrite log from within my .htaccess, so that's not an option...


Thanks for your help already!

Rein
#9

[eluser]Rein Van Oyen[/eluser]
Hello there again,

is there anybody who can help me out? I can imagine more people use this approach in CI, but it seems noone is having a hard time figuring out the modrewrite rules. I would highly appreciate any help, since I'm having this problem for a loooong time now. Smile

Thanks for your understanding.

Rein
#10

[eluser]dianikol85[/eluser]
Hi there. I guess you want to have a front end and a backend area.

the way i did it is the following:

1) Use
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
to remove the index.php from all URLs

2) I create two folders under controller,model,views, and i call them admin, frontend

3) In the routes.php add this line
Code:
$route['admin'] = 'admin/your_controller';


so when you type int the browser http://www.yoursite.com/admin it will redirects you in to the 'your_controller' controller which is under controller/admin/your_controller.php

I hope this is what you were looking for




Theme © iAndrew 2016 - Forum software by © MyBB