0

I get how to remove index.php from CI urls overall. The following works fine:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /crm/v2/index.php?/$1 [L]

However, it interfers with other code on the live site. This new CI version i'm adding is in a subdir named v2. Thus the layout is something like:

-originalDir
  --v2
-otherDirs
-.htaccess
-etc...

So in essence urls come out something like:

// Original page
https://www.site.com/originalDir/somepage.htm
// And this exist too
https://www.site.com/originalDir/index.php

// My new stuff
https://www.site.com/originalDir/v2/index.php/controller/etc...
// Desired effect withOUT affecting the original sites index.php page
//     aka, the below is what i WANT but NOT getting!
https://www.site.com/originalDir/v2/controller/etc...

I can code in a lot of languages, but never a lot of experience with these htaccess rewrites. Any ideas on how to make it rewrite index.php for ONLY the codeigniter sub-directory? I've tried a few things that seem to work locally, but not on the live server. Not sure the exact structure of rewrite code.

4
  • Your htaccess actually looks right, have you removed the index.php from the config.php file? Commented Apr 3, 2013 at 16:47
  • it is right, as i stated before, however there is old code on that same site that stops working. Thus i need an alternate solution. Commented Apr 3, 2013 at 16:57
  • Yeah, but what I meant is it really doesn't look like it should be affecting anything above that level. I'm not great with htaccess either though so... Commented Apr 3, 2013 at 17:01
  • @RickCalder NP, and thanks for the inquiry. I found my answer below. Putting the alternate solution in the v2 directory seems to be doing exactly as I intended and not affecting the rest of the site! Commented Apr 4, 2013 at 12:15

2 Answers 2

1

Assuming you want to only rewrite rules in the CI directory, and not point any URLs outside of that directory to it...

Change your RewriteRule to match only URI's that start with your CI directory.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^crm/v2/(.*)$ /crm/v2/index.php?/$1 [L]

Alternatively, you can put an .htaccess file in your /crm/v2 directory, and specify a RewriteBase.

RewriteEngine on
RewriteBase /crm/v2/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Sign up to request clarification or add additional context in comments.

1 Comment

Your alternate solution was exactly what I needed. So far, it seems to be working just fine with 0 interference! Will post back if I notice any problems. Until then, thank you!
1

Have you tried using RewriteBase?

RewriteEngine On
RewriteBase /crm/v2
RewriteRule ^(.+)$ index.php?/$1 [L]

I have not tested this specifically with your information but this is from a template that I use for some of my projects.

Here is the documentation for RewriteBase: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase

I hope this helps!

1 Comment

Given you a +1 for the documentation lead, though in the end, the alternate answer provided by @Cryode has worked perfect! Thanks for all the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.