0

I have Codeigniter 3 project in root directory. I need to use it with kohana other project which is in subfolder (admin). I need to make redirect, when I will type mysite.xyz/admin that will redirect me to subfolder admin, where are kohana files: index.php etc.

Now CodeIgniter think that admin is a controller.

My .htacces file:

<IfModule mod_rewrite.c>

  RewriteEngine On
  RewriteBase  /projekty/folder/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
  RewriteRule admin/^(.*)$ /admin/ [L]

</IfModule>
<IfModule !mod_rewrite.c>

  ErrorDocument 404 /index.php

</IfModule>

Have any ideas, how to solve that? I was trying to find some solutions, but no success.

Here is Kohana .htaccess:

RewriteEngine On
RewriteBase /projekty/folder/admin/

###### Add trailing slash (optional) ######
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [L,R=301,NE]

RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*)home/u343855449/public_html/projekty/folder/admin/index.php/(.*)$ /$1$2 [R=301,L,NE]

RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|media)
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?kohana_uri=$1 [L,QSA]
zyx4sdk
  • 320
  • 4
  • 14

1 Answers1

1

your admin rule is in the wrong place. It needs to come before the CI rules. Put it below the rewritebase. Try these rules.

<IfModule mod_rewrite.c>

  RewriteEngine On
  RewriteBase  /projekty/folder/

  RewriteRule ^admin/(.*)$ /admin/$1 [L]

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

</IfModule>

Actually you really don't need the admin rule. Just tell it to ignore admin in the CI rules as below.

<IfModule mod_rewrite.c>

      RewriteEngine On
      RewriteBase  /projekty/folder/

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

    </IfModule>
zyx4sdk
  • 320
  • 4
  • 14
Panama Jack
  • 24,158
  • 10
  • 63
  • 95
  • Ok it works, thank you! But now I have a problem with Kohana part. Main page works ok - when i type `mysite.xyz/projekty/www.nurkowanie.travel.pl/admin` page load, but when I type some sub page of it - then it fails and redirect to `mysite.xyz///` I edited the post and added Kohana .htaccess. I changed paths in Kohana cofiguration. – zyx4sdk Oct 30 '15 at 22:27
  • I don't know anything about Kohana, but it seems there are other rewriterules for it http://kohanaframework.blogspot.com/2010/12/kohana-3-htaccess-that-works-on.html and http://stackoverflow.com/a/968073/330987 – Panama Jack Oct 31 '15 at 04:03
  • Ok, so thaks a lot for solution with CI! – zyx4sdk Oct 31 '15 at 16:49