Forum Moderators: phranque

Message Too Old, No Replies

Stop Wordpress from hi-jacking CodeIgniter URLs using .htaccess

         

Jakobud

8:02 pm on Aug 2, 2010 (gmt 0)

10+ Year Member



Wordpress installed at root web directory:

/var/www/html/


CodeIgniter installed in a sub-directory:

/var/www/html/ciapp/


When I access
http://www.mysite.com/ciapp/
the main CI controller is accessed and executed correctly.

However, if I try to access my main CI controller directly like so:

http://www.mysite.com/ciapp/main/


I get Wordpress's 404 page. Also, if I attempt to access a function of my main controller like this:

http://www.mysite.com/ciapp/main/myfunction/


I also get the same 404 page.

So basically, Wordpress is ignoring the /ciapp/ directory by default, but its not ignoring any URL requests that are added to it. Here is my Wordpress .htaccess:

# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress


So what kind of RewriteCond do I need to add to the Wordpress .htaccess for it to ignore the /ciapp/ directory and anything URI request that uses that directory as well?

I tried this:

RewriteCond %{REQUEST_URI} !^/?ciapp


But it didn't seem to have any effect.

So I think that what I need are two things:

1. A way to tell Wordpress to ignore any requests to the /ciapp directory
2. If the /ciapp/ directory is accessed, use the /ciapp/index.php instead of /index.php

g1smd

10:40 pm on Aug 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteCond %{REQUEST_URI} !^/ciapp


Clear your browser cache before testing.

Make sure that MultiViews and AcceptPathInfo are OFF.

Jakobud

10:58 pm on Aug 2, 2010 (gmt 0)

10+ Year Member



That didn't work. Here is my .htaccess now:



# BEGIN WordPress

<IfModule mod_rewrite.c>

acceptpathinfo off
Options -Multiviews

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/ciapp
RewriteRule . /index.php [L]

</IfModule>

# END WordPress

jdMorgan

11:21 pm on Aug 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there any mod_rewrite code associated with codeigniter in this .htaccess file?

Is there any mod_rewrite code associated with codeigniter in a/the /ciapp/.htaccess file?

Basically, the RewriteCond exclusion should have worked, so the problem is elsewhere.

Note also that you can speed up your site noticeably by tweaking that WP rule-set, but that can wait until your primary problem is corrected.

Jim

Jakobud

11:43 pm on Aug 2, 2010 (gmt 0)

10+ Year Member



The .htaccess I posted is the .htaccess in its entirety. There is no /ciapp/.htaccess

jdMorgan

12:06 am on Aug 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In that case, codeigniter must be using AcceptPathInfo to 'input' things like /main/myfunction/ -- otherwise, this path information would be taken as a literal filepath, and you would get a 404 as reported.

If that is the case, then you'll need the RewriteCond exclusion and "AcceptPathInfo Off" in /.htaccess, and "AcceptPathInfo On" in /ciapp/.htaccess

You might want to have a look at the codeigniter docs to confirm that this is how the controller knows what function is desired. If not, then there's likely some other rewrite/alias code missing somewhere...

Jim

Jakobud

12:36 am on Aug 3, 2010 (gmt 0)

10+ Year Member



Thanks for the input. Unfortunately that hasn't seemed to work. I posted the same question over on SF here

[serverfault.com...]

Can you take a look at that guy's response and let me know what you think about it? I tried to apply that code in the .htaccess but I might have been putting it in the wrong place.

jdMorgan

1:47 pm on Aug 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That reply indicates that you are missing code to 'map' codeigniter requests to the controller.

This code should have been provided in the CI package, or at least it should have been given in the documentation. I assume that you checked before posting...

Because I don't use CodeIgniter, and because the reply you cited has faults in the code, the following is just a guess and may require tweaking. In order for this to work, codeigniter must "import" the requested URL-path from a server variable in order to know what function to do. If this code does not work at all, then I'll have to refer you to codeigniter's Web site and/or forum if no-one else here at WebmasterWorld answers this question.

In /.htaccess :

Options +FollowSymLinks -Indexes -Multiviews
#
RewriteEngine on
RewriteBase /
#
# Begin CodeIgniter
RewriteCond $1 \.(php|gif|jpe?g|png|ico|css|js)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ciapp/(.+)$ /ciapp/index.php [L]
# End CodeIgniter
#
# BEGIN WordPress
RewriteCond $1 \.(php|gif|jpe?g|png|ico|css|js)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php [L]
# END WordPress

All access control and external redirect rules (such as hostname and index page canonicalization used to avoid duplicate-content problems) must precede this internal rewrite code.

Jim