Wordpress/Codeigniter URL issues when installed on same server - php

I have installed my wordpress installation on my server root e.g mydomain.com & codeigniter installed in subdirectory named ci e.g mydomain.com/ci. When I try to access my wordpress site it works fine, but when I try to access any of my ci controllers e.g mydomain.com/ci/signup it throw 404 Page Not Found CI error. but it worked fine for my default home controller. I have searched for solution & tried many of them but any one of them is not worked in my case.
here is the rewrite rules in .htaccess for my both installtion.
mydomain.com/.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
mydomain.com/ci/.htaccess
RewriteEngine on
RewriteBase /ci
RewriteCond $1 !^(index\.php|user_guide|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

I think the problem is with wordpress .htaccess file. We should have to route the request that is for ci to ci folder.
This code might help, add this to wordpress .htaccess file
RewriteRule ^$ ci/$1 [L]
RewriteRule ^(.*) ci/$1 [L]

Related

404 Issues sending form data from Wordpress page to CodeIgniter page

I have installed WP at my root directory and moved the CI application that was at the root to a sub-folder called "members." The WP pages are working just fine, but when I try to sign into the CI application, using my log in form on a WP page, I'm getting back a 404 error. I have a feeling this has something to do with routing and WP overriding things but I've been unable to figure this out so far.
.htaccess at root:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(info|info/.*)$
RewriteCond %{REQUEST_URI} !^/(members|members/.*)$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I wanted the info and members controllers in CI to still be accessible from WP.
I can tell the CI page is being hit because I can still redirect the browser by adding a line in the controller, yet when I try to actually post data with the form and look at the Network activity in Chrome, I can see the 404 is coming back on the page I'm posting to.
UPDATE:
Okay, I've been able to isolate this to being a routing issue, the problem is Wordpress is functional, but CodeIgniter isn't. I realize there's no modrewrite rules that apply to the /members/ directory. Here's where I'm at:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(members|members/.*)$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /members
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Any thoughts?
It was a routing issue! I didn't realize I needed to put the Codeigniter specific .htaccess entries at the subfolder where the Codeigniter application resided. Of course it was that simple!

How to redirect or load a website placed inside a WordPress directory?

I have a WordPress website hosted at the root folder and in the same root another CodeIgniter website placed in a folder.
The CodeIgniter site is not loading now. IT shows page not found error
The URL structure will be: http://website.com - wp site and http://website.com/wi/ver1/
which means I put the CodeIgniter site in a folder wi/ver1/.
The htaccess code for the base wp site is :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
And the httaccess inside the wi/ver1 directory is :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|js|images|robots\.txt)
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
Could you please try to help to solve this issue?
First of all check your site_url in wordpress project. Then change your RewriteRule . /index.php [L] with RewriteRule ^(.*)$ index.php?$1 [L] because it contains double backward slashes in your url .
if you want to load your codeigniter site, change base_url in config.php file, add your folder name that url
For example :$config['base_url'] = http://yoursite.com/folder_name/.

404 Error - codeigniter and htaccess

I uploaded my project to a sub domain of my website. On that sub domain I installed wordpress on it and installed codeingiter to directory called app. The default controller is set to login which shows up when I go to the app/ url but once I click on any of the links "app/create-account or app/login" it takes me to wordpress default 404 error page. I am using codeingiter 3 and have been trying for a few days to get this working correctly. My class names are according to the styles required (ucfirst) and I believe it is something to with my htaccess file. Everything works fine on my localhost.
Current htaccess file in my codeingiter directory "/app/"
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]
Current wordpress htaccess file
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/app(/*)? - [L,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any suggestions are much appreciated :)

mod_rewrite for multiple application in codeigniter

I am new to url re-writng and is currently facing problems with rewriting url for multiple applications in codeigniter. I have scanned the whole stackoverflow with some potential answers but it is still not solving my problems entirely
My directory at the root is as such
-application
--administrator
--frontend
What I am looking for is for my users to access my web site (frontend) with http://www.mydomain.com/ And my admin (backend) as http://www.mydomain.com/admin/
my current .htaccess is as such
<IfModule mod_rewrite.c>
RewriteEngine On
# If the user types just "admin".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin$ administrator.php [L,QSA]
# If the user enter in any admin section, like "admin/section".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin\/(.*)$ administrator\.php/$1 [L,QSA]
# If the user types any site section, like "site/section".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index\.php/$1 [L,QSA]
ErrorDocument 404 /index.php
</IfModule>
code from CodeIgniter multi-application .htaccess problem
I can get what I desire at the front end with the above .htaccess, but I can't get it working on my back end. Basically, www.domain.com/admin gives a 404 page not found error.
Please advice me on the problem. Also, please guide me on where I should place this .htaccess file? at the root? inside the application folder? or inside the frontend and administrator folder respectively.
Many thanks.
Regards.
Why not something like this in your root directory.
RewriteEngine on
RewriteCond $1 !^(index\.php|update\.php|assets|admin|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ index.php/$1 [L]
This will basically ignore any directories such as "admin" to route to the frontend application. You will have to set your config.php and remove index.php from the controller.
Found a way to work with this problem already. It is not a very smart way of doing it but it at least worked.
First, I created an 'admin' folder in the root, with a copy of the application's index.php
Which effectively make my directory looking like this.
-admin
--.htaccess
--index.php
-application
--frontend
--administrator
-index.php
-.htaccess
For this solution you will need to have two .htaccess files in different location.
For the .htaccess at the root, it should look like this.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|update\.php|administrator\.php|assets|admin|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
For the .htaccess in the admin folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
While this works on localhost, it is noteworthy that it may not work on rented servers because the file system in your host may be different.

.htaccess in subfolder

The main site runs WordPress with .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I'm going to create an CodeIgniter app in subdirectory site.com/online/
If simply add CI .hta file in subfolder it wouldn't work. CI .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|img|styles|js)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Is it possible to combine two .htaccess files or to do something with .htaccess in CI subfolder?
Thank you.
UPD.
Thank you for answers, I've tried all variants, and eventually moved project to subdomain.
First thing, your .htaccess should be like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} !^GET\s/+online/ [NC]
RewriteRule . /index.php [L]
</IfModule>
#Then add this for CI handling in the same .htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !index\.php [NC]
RewriteRule ^online/(.*)$ online/index.php?/$1 [L,NC]
Then you can remove (or rename) .htaccess in the online subfolder.
Try this for the codeigniter .htaccess:
RewriteEngine on
RewriteBase /online
RewriteCond $1 !^(index\.php|robots\.txt|img|styles|js)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Otherwise all requests to that subfolder would be redirected down to wordpress.
Are you setting AllowOverride? According to the docs you need to allow FileInfo overrides for mod_rewrite.

Categories