Welcome Guest, Not a member yet? Register   Sign In
mod_rewrite for multiple applications
#11

[eluser]vitoco[/eluser]
tested and working on my dev machine
Code:
Options +FollowSymLinks
RewriteEngine On

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

Saludos
#12

[eluser]vbsaltydog[/eluser]
[quote author="vitoco" date="1328501974"]tested and working on my dev machine
Code:
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule admin/^(.*)$ admin.php/$1 [L] //  You dont need the carat character
RewriteRule public/^(.*)$ public.php/$1 [L] //  You dont need the carat character

Saludos[/quote]
#13

[eluser]Aken[/eluser]
He should use the caret character, at the start where it should be.
Code:
Options +FollowSymLinks
RewriteEngine On

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

[eluser]vbsaltydog[/eluser]
I meant that he didn't need it where he had it. Smile
#15

[eluser]@robertotra[/eluser]
As regards to the solutions proposed, I see that if we need to differentiate between totally differently applications, best way is by using url-rewriting in .htaccess (but remembering that we need to setup the general home page of our website either as application independent or redirecting to the home page of the main application) while if we need just to differentiate between public pages and administration pages (as it seems this case) it is better to use controllers subfolders, even because administration tasks will probably require same models of the public parts to retrieve data and totally separating applications will cause to duplicate code between different applications, generating a maintenance nightmare :-)

Maybe it is worth to remind also that creating a controllers subfolder (especially if for administration purposes) works better if we add CI's url routing rule to set up a default page for the subfolder when it is the only part present in the URI (to show a login form as example) avoiding the default redirection to application home page, that might be not the best solution for all cases.

Bye
Roberto
#16

[eluser]obay[/eluser]
I couldn't get your suggestions to work, so I just followed CroNiX's suggestion. Here's my final .htaccess

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

Thanks all!
#17

[eluser]Aken[/eluser]
Also as an update to anyone interested, we made a mistake in that RewriteCond conditions are only valid for the next RewriteRule. Once a RewriteRule has been defined, the conditions reset back to none for the next one. So you need to duplicate RewriteCond for multiple rules.

Code:
Options +FollowSymLinks
RewriteEngine On

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

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

Also obay, make sure you create something to handle calls to your root folder, which would normally default to index.php (like mywebsite.com would default to mywebsite.com/index.php) - so make sure you do something to keep your main .com from having a 404 error.
#18

[eluser]obay[/eluser]
[quote author="Aken" date="1328608375"]Also obay, make sure you create something to handle calls to your root folder, which would normally default to index.php (like mywebsite.com would default to mywebsite.com/index.php) - so make sure you do something to keep your main .com from having a 404 error.[/quote]

@Aken, how would I do that, given my current .htaccess?
#19

[eluser]Aken[/eluser]
Personally I would leave the public application named index.php.
#20

[eluser]Kenneth Allen[/eluser]
[quote author="Aken" date="1328608375"]Also as an update to anyone interested, we made a mistake in that RewriteCond conditions are only valid for the next RewriteRule. Once a RewriteRule has been defined, the conditions reset back to none for the next one. So you need to duplicate RewriteCond for multiple rules.

Code:
Options +FollowSymLinks
RewriteEngine On

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

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

Also obay, make sure you create something to handle calls to your root folder, which would normally default to index.php (like mywebsite.com would default to mywebsite.com/index.php) - so make sure you do something to keep your main .com from having a 404 error.[/quote]

My situation is a little bit different. I have an application developed with CI called SMaLL, which has been implemented on several non-CI (but PHP based) web sites by simply adding the SMaLL folder to the root directory for the main site. By simply appending the text /SMaLL to the regular URL for the main site the SMaLL system is invoked cleanly. So if their site name was main.myhostsite.com, they would invoke my application using the URL main.myhostsite.com/SMaLL, and an RESTful portions added by my application would append to that string.

Recently I was asked to rewrite an existing site and was given approval to use CI, which I did. Now they want me to add SMaLL as a part of that site as well. So, if the URL for the new site is trial.myhostsite.com then they want to be able to use my application on their site like they did with the old one using trial.myhostsite.com/SMaLL.

Note that this is not quit the same as two CI applications in the same site, but rather one under the other.

So, as with the the previous site, I copied my SMaLL folder into the root folder for the new CI based site, but I cannot seem to convince the top level code to pass my URL requests down to the SMaLL application cleanly. For example, if I use the URL trial.myhostsite.com/SMaLL/dosomething/3, which should invoke a method named do something in the controller with the path ~/SMaLL/application/controllers/small.php, it seems to get to the default controller in SMaLL and does not pass along any of the other segments on the URL.

The following is the .htaccess file in the root of the trial site folder:

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|Assets|Documents|Tutorials|Photos|Temp)
RewriteRule ^(.*)$ /index.php/$1 [L]

And the following is the .htaccess file in the SMaLL folder:
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|Documents|Tutorials|Photos|Temp)
RewriteRule ^(.*)$ /SMaLL/index.php/$1 [L]

What changes do i need to make to the root .htaccess file to permit it to pass control to the SMaLL application? I tried modifying it as shown below, but that did not seem to achieve anything.
RewriteEngine on
RewriteCond $1 !^(index\.php|Assets|Documents|Tutorials|Photos|Temp)
RewriteRule ^SMaLL/(.*)$ /SMaLL/index.php/$1 [L]

RewriteCond $1 !^(index\.php|Assets|Documents|Tutorials|Photos|Temp)
RewriteRule ^(.*)$ /index.php/$1 [L]




Theme © iAndrew 2016 - Forum software by © MyBB