Welcome Guest, Not a member yet? Register   Sign In
htaccess, subfolders and phpbb
#1

[eluser]Cappinator[/eluser]
Hi,

First of all I wish to apologize if the solution to my problem is already on this forum somewhere. I looked for about two days and couldn't find it.

Here's my dir structure:
Code:
* htdocs
   * CI
      * css
      * system
      - index.php
      - .htaccess
   * forum
      - all phpbb files

My .htaccess file in the CI folder:
Code:
RewriteEngine on
RewriteRule ^$ /CI/index.php [L]
RewriteCond $1 !^(index\.php|img|css|js|video_files|robos\.txt|favicon\.ico)
RewriteRule ^(.*)$ /CI/index.php/$1 [L]

Lines in my config.php
Code:
$config['base_url'] = "http://www.mydomain.com/CI/";
$config['index_page'] = "";

There are now 2 problems:
1) To get to my CI site, I have to type http://www.mydomain.com/CI/welcome
Everything works, but I find this "/CI" route is annoying. I'd prefer my site to be under http://www.mydomain.com/welcome, and all links should point to pages under http://www.mydomain.com, without the /CI

2) The forum works if I type in the url http://www.mydomain.com/forum, but when I try to link to it from within my CI application, I can't get it to work. Since CI can only see as far as the /CI folder and not beneath that, I can't link to the forum from within the application.

I'm new to php and have only dabbled in it in the past, so there might be an obvious solution to this.

Can anyone help me?

Christophe
#2

[eluser]Cappinator[/eluser]
Ok, I changed some things. First of all, I added a .htaccess file to my htdocs folder

Code:
* htdocs
   - .htaccess
   * CI
      * css
      * system
      - index.php
      - .htaccess
   * forum
      - all phpbb files

The .htaccess file in the htdocs folder is like this:
Code:
RewriteEngine on
RewriteCond $1 !^(forum)
RewriteRule ^(.*)$ /CI/$1 [L]

I think this solves my problem of having /CI in all my URI's when using my CI application.

But now, for some reason, my CI application is no longer working entirely.

What is working?
- http://www.mydomain.com/forum works
- http://www.mydomain.com works, it serves me my default CI page, so CI is working
- http://www.mydomain.com/blog doesn't work and I don't have a clue why not
- http://www.mydomain.com/CI/blog doesn't work either...

I'll keep looking, but I'm hoping for someone who can give me the answer before I spend days looking for this.
#3

[eluser]Cappinator[/eluser]
Ha! Never mind! I found it!

I had tried rerouting blog to CI/blog and forgot to take that route out.

It works now.

Two days of looking on the forum, I should have looked for the solution myself :p
#4

[eluser]richard_ctv[/eluser]
You may find it simpler overall to put index.php and the CI system folder in htdocs (dispensing with the CI folder) and put forums in the rewrite condition.

that way anything that is not in the rewrite cond get served by CI.

I do this and it works seamlessly.
#5

[eluser]Cappinator[/eluser]
And I solved problem 2) as well.

For any fellow newbies who are looking for a similar solution and aren't familiar with .htaccess, here's the entire problem and solution.

Suppose you have an external php application like phpbb and you wish to run it on the same server, but separate from CodeIgniter.

Do the following:
1. Make a folder for your non-CI php application, I'm using phpbb as example, so I'm naming the folder "forum"
2. Make a folder to hold your CI framework and application, "CI"

The dir structure should be like this:
Code:
* (root folder: www, htdocs, etc...)
  * forum
    - all php files for this app go here
  * CI
    * system
    - index.php

3. Create a new file in your web host root folder and name it ".htaccess"

Code:
* (root folder: www, htdocs, etc...)
  - .htaccess (<-- it goes here)
  * forum
    - all php files for this app go here
  * CI
    * system
    - index.php

4. Edit the ".htaccess" file:
Code:
RewriteEngine on
RewriteCond $1 !^(forum)
RewriteRule ^(.*)$ /CI/$1 [L]

If for some reason, you have several non-CI php apps, add a folder for that one in the same way as for "forum" and change the appropriate line of the .htaccess file like this:
Code:
RewriteCond $1 !^(forum|other_php_app)

5. Create a new file in your "CI" folder and name it ".htaccess" as well. You will now have two ".htaccess" files, one in your web root folder and one in the "CI" folder.
Code:
* (root folder: www, htdocs, etc...)
  - .htaccess
  * forum
    - all php files for this app go here
  * CI
    * system
    - index.php
    - .htaccess (<-- it goes here)

4. Edit this ".htaccess" file:
Code:
RewriteEngine on
RewriteRule forum ../forum

This line makes it possible to link to the forum php application that is outside the CI folder. You can add lines for other php apps in the same way.

This is also the place where you would place .htaccess lines that remove the need for index.php in your URI.

That's it.

I apologize for the php/Apache/CodeIgniter guru's who had to read through this and found all this stuff too easy to merit a step-by-step explanation. Us newbies sometimes need that Smile
#6

[eluser]Cappinator[/eluser]
[quote author="richard_ctv" date="1185546940"]You may find it simpler overall to put index.php and the CI system folder in htdocs (dispensing with the CI folder) and put forums in the rewrite condition.

that way anything that is not in the rewrite cond get served by CI.

I do this and it works seamlessly.[/quote]

That would work and I appreciate your input. But I wanted non-CI and CI applications totally separated through folders... It helps me keep things more organized.
#7

[eluser]richard_ctv[/eluser]
[quote author="Cappinator" date="1185548210"]
That would work and I appreciate your input. But I wanted non-CI and CI applications totally separated through folders... It helps me keep things more organized.[/quote]

Fair enough. :-) I'll explain a bit more as it may be helpful to someone else...

I have done something like this on a couple of projects now. I normally move the application folder out of the system folder, and rename it.

This has also meant that I can have more than one CI based application folder and I can see everything at the top level.

htdocs
non_ci_app_1
non_ci_app_2
non_ci_app_3
ci_system
my_ci_application_1
my_ci_application_2
index_ap_1.php
index_ap_2.php

I put the rewrite rules in the main apache site file (I have full server access) as this avoids the performance overhead of .htaccess files.




Theme © iAndrew 2016 - Forum software by © MyBB