Installing CodeIgniter on root and WordPress in sub-directory
Asked Answered
F

4

9

I want to create a website where the main pages will be served from CodeIgniter. I will use Wordpress in the /blog/ sub-directory to host the blog. Thats it! I want nothing else. Just to make sure that:

example.com/somepage/ calls a CI controller where as example.com/blog/some-post/ is handled by Wordpress.

I don't need any kind of integration or interaction between CI and WP.

Is it possible to install in that way? If not, any workarounds so that I can achieve the objectives?

Thanks and Regards, Masnun

Fascinator answered 24/3, 2010 at 18:38 Comment(0)
C
9

I suspect you could get this to work using an .htaccess file in the root directory of your site. If blog is the name of the subdirectory where WordPress is installed, and you want example.com/blog to be handled by WordPress, try this to see if it helps:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|blog)
RewriteRule ^(.*)$ /index.php/$1 [L]
Calk answered 25/3, 2010 at 17:57 Comment(3)
Thanks. From the look of it, it should work. I'm gonna try this.Fascinator
That's the way we integrate CI with other apps/sites. This could be declined to work in both ways : CI app into wordpress dir, and wordpress inside CI app dir.Subsequent
@Rich Miller Its not working for me. can you check question #32535301Municipalize
S
2

+1 with Rich's method

Additionnaly, if you're using a .htaccess file like the one suggested on CI doc, it should work by dropping WP directory directly into web root dir.

RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
#Submitted by Michael Radlmaier (mradlmaier)


RewriteCond $1 !^(index\.php|robots\.txt|corporate|assets)
RewriteRule ^(.*)$ index.php/$1 [L]

Because of the RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_FILENAME} !-d any call made directly to a real file on webserver would be served directly by Apache, other uris wil be handled by CI's routing mecanism.

Notice we used a last RewriteCond directive to exclude calls to certains files, including our assets dir (containing images/css/js static files) and 'corporate' dir which contains in this case a blog.

Although this example do not use wordpress, it has its own url-rewriting and routing system.

In a matter of conclusion, you'll have use a specific RewriteCond statement if you want to use WP url-rewriting, if not it could work without it.

Subsequent answered 11/5, 2010 at 9:57 Comment(1)
This answer worked for me very accurately as the above marked correct one messed up my assets filesPloce
D
1

It should work just as you described it without any complicated configuration. Just install codeigniter in your root directory and then create a blog directory and put wordpress in there.

Disoblige answered 24/3, 2010 at 20:13 Comment(0)
I
0

You never mention which server you are using. I was getting the same error for my website too. Later I discover htaccess does not work with nginx.

So I simply make 2 location block into my nginx config file.

location / {
                # Check if a file or directory index file exists, else route it to index.php.
                try_files $uri $uri/ /index.php;
http2_push_preload on;
        }
location /updates/ {
  try_files $uri $uri/ /updates/index.php;
}

Now both my codeigniter and Wordpress is working.

Impower answered 22/3, 2023 at 6:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.