If controler doesn't exist, route to physical folder

I’m slowly re-writing a site, and I need the old site and the new Yii site to co-exist during the re-write. What I’m trying to do is have the Yii site re-direct to the old site unless I have written a controller for a specific page.

Here is an example:

Right now if someone comes to

/blog12/posts.php, I need yii to redirect to /oldsite/blog12/posts.php

Once I have written the necessary yii code and the post controller exists I need

/blog12/posts.php to redirect to /blog12/posts/ controller

What is the best way of achieving this? urlManger? htaccess? or site/error controller? Is there anything written about slow Yii deployments to existing sites? I can’t seem to find anything on the topic, everyone assumes you are starting from scratch.

Thanks in advance!

I use htaccess, but inverse order, if no folder or file, redirect to php

RewriteEngine on

#is not a file

RewriteCond %{REQUEST_FILENAME} !-f 

#is not a dir

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

Yes, that’s a great idea, but in my case /blog12/ will remain a physical folder until everything is re-written. So I need /blog12/ to be ignored sometimes but not other times, thus the creation of the /oldsite folder that houses the old site…

I misread your post the 1st time. You are right, my solution above is no good.

The best solution I can think of is to add a rule in htaccess, check if the file exists in the old{REQUEST_FILENAME } folder and if it does rewrite to it

I wouldn’t know the exact code to put in it tho.

My first thought was urlmanager.


Just in case anyone else runs into this issue, here is the mod_rewrite for .htaccess to check if files exist in a certain directory (‘old_site’ in this one) and route to them if they do, if not route to index.php and let yii take over:

Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on

RewriteBase /

# if directory doesn't have a trailing slash and doesn't have a . in it add slash and re-direct

RewriteCond %{DOCUMENT_ROOT} -d

RewriteRule ^([^.]*[^/])$ $1/ [R]

# if directory exists, re-write to root

RewriteCond %{DOCUMENT_ROOT}/000__teams3/$0 -d

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

# if file exists, re-write to root

RewriteCond %{DOCUMENT_ROOT}/000__teams3/$0 -f

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

# else forward all to index.php and let yii takeover

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule . index.php