URGENT: mod_rewrite help, CodeIgniter + WordPress (WP)

29 views
Skip to first unread message

.Net2Php

unread,
Jul 17, 2009, 10:09:45 PM7/17/09
to NZ PHP Users Group
I have a CodeIgniter application with WP installed in /cms/ folder
(under root). I am able to access WP pages provided /cms/ is in the
URL. However, I want to eliminate the /cms/ part of the URL. So:

Instead of: www.domain.com/cms/my-article-in-wp/
I want: www.domain.com/my-article-in-wp/

I assume I need to do something with the .htaccess file in /cms.
Currently, here is what I have in the .htaccess of the /cms/ folder:

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

The root .htaccess has the standard CodeIgniter .htaccess file. I
tried putting the following in the root .htaccess, but it didn't work:

RewriteRule ^cms/(.*)$ $1 [NC,L]

I guess there might be some sort of conflict??? Anyway, if anyone can
point me in the right direction, it would be much appreciated.

Thanks,
KIP

Berend de Boer

unread,
Jul 18, 2009, 12:52:26 AM7/18/09
to nzp...@googlegroups.com
>>>>> "Net2Php" == Net2Php <kiph...@gmail.com> writes:

Net2Php> I have a CodeIgniter application with WP installed in
Net2Php> /cms/ folder (under root). I am able to access WP pages
Net2Php> provided /cms/ is in the URL. However, I want to
Net2Php> eliminate the /cms/ part of the URL. So:

Net2Php> RewriteRule ^cms/(.*)$ $1 [NC,L]

Wouldn't it be the other way around?

RewriteRule ^(.*)$ /cmd/$1 [NC,L]

--
Cheers,

Berend de Boer

.Net2Php

unread,
Jul 20, 2009, 3:44:25 AM7/20/09
to NZ PHP Users Group
Barend,

Thanks for the suggestion. It works -- kindda.

When I put it in my root .htaccess, my CodeIgniter application stopped
working. When I tried to put it in .htaccess of the /cms/ folder, I
was getting server errors. There must be a conflict somewhere???

On Jul 18, 4:52 pm, Berend de Boer <ber...@pobox.com> wrote:

Karl

unread,
Jul 20, 2009, 4:25:35 AM7/20/09
to nzp...@googlegroups.com

Typo in Berend's code... replace "cmd" with "cms"...

*********** REPLY SEPARATOR ***********
---
Karl
Senior Account Manager
www.KIWIreviews.co.nz ... Where Your Views Count
Please consider the environment before printing this email.

.Net2Php

unread,
Jul 20, 2009, 7:08:40 AM7/20/09
to NZ PHP Users Group
Yes, I caught the typo. The problems I am having as sans-typo.
> Senior Account Managerwww.KIWIreviews.co.nz... Where Your Views Count

Matias Gertel

unread,
Jul 20, 2009, 5:59:31 PM7/20/09
to nzp...@googlegroups.com
Try this on your top folder, and remove the .htaccess from the /cms folder:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^cms/(.*)$ /cms/index.php [L,QSA]
# Or maybe like this:
#RewriteRule ^cms/(.*)$ /cms/index.php/$1 [L,QSA]

#Now the code igniter part:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php [L,QSA]

Matias Gertel
Freelance Web Development & Coding

.Net2Php

unread,
Jul 22, 2009, 12:07:17 PM7/22/09
to NZ PHP Users Group
Matias,

I tried your suggestion, but it still didn't work.

- CodeIgniter still works fine
- WordPress pages still accessible with /cms/ in the URL
- WordPress pages without /cms/ in the URL results in CodeIgniter 404
page

Here's my .htaccess file:

Options -Indexes
Options +FollowSymLinks
Options -MultiViews

DirectoryIndex index.php

<IfModule mod_rewrite.c>

RewriteEngine on
RewriteBase /


#-----------------------------------------------------------------------------
# Integrate WordPress per
# http://groups.google.com/group/nzphpug/browse_thread/thread/e35d10e39ec0d95?hl=en

#-----------------------------------------------------------------------------
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^cms/(.*)$ /cms/index.php [L,QSA]
#RewriteRule ^cms/(.*)$ /cms/index.php/$1 [L,QSA]



#-----------------------------------------------------------------------------
# CodeIgniter

#-----------------------------------------------------------------------------
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]
#RewriteRule ^(.*)$ /index.php/$1 [NC,L,QSA]


#-----------------------------------------------------------------------------
# Secure .svn directories

#-----------------------------------------------------------------------------
RewriteRule (\.svn)/(.*?) - [F,L]

Did I miss something?

Matias Gertel

unread,
Jul 22, 2009, 5:50:03 PM7/22/09
to nzp...@googlegroups.com
Ok, now I'm re-reading your original post and a basic issue comes to mind:
Because both wordpress and codeigniter handle their redirects through php and not apache, apache has no way of knowing if a particular URL was handled correctly by either, so apache rules don't really count here. This means you'll have to put some kind of hack in either of the applications to send the request to the second app if the first app couldn't handle the URL. Maybe you could make somehow your CI app a WordPress plugin, or the other way round. Just a thought. I'm not too familiar with WP or CI but the cheeky way of doing it is putting the code in the error page controller. 

Matias Gertel
Freelance Web Development & Coding

.Net2Php

unread,
Jul 22, 2009, 6:52:48 PM7/22/09
to NZ PHP Users Group
Matias,

Thanks for the help. There is a hack for this, but it involves going
into the core of CI and WP -- and initial attempts have not been so
successful for me. I just had to exhaust the mod_rewrite approach
before trying to hack these applications again. Thanks.

Harvey Kane

unread,
Jul 23, 2009, 3:03:27 AM7/23/09
to nzp...@googlegroups.com
Just removing the 'urgent' from the subject line - it's playing havoc
with my email systems and I gather it's not actually urgent anymore :)

Harvey.
--
Harvey Kane

Germany
-Mobile: +49 15223942886

New Zealand:
-Office / Mobile: +64 9 950 4133

Email: har...@harveykane.com
If you need to contact me urgently, please read my email policy www.ragepank.com/email/

Reply all
Reply to author
Forward
0 new messages