I am currently having an issue with the URL manager. I added new rules but all the old links (before the rules) do not work anymore and redirect to the home page.
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
You configured urlManager to use path format (site/controller/action/param/value) and index.php hiding, but your old url’s are in get format (site/index.php?r=controller/action¶m=value). You should still be able to explicitly include index.php when accessing the site, but the path format will pose a problem. To the best of my knowledge you’ll have to set urlFormat=‘get’.
OK so finally, decided to add a new check in the bootstrap directly (index.php). So basically added a switch for the GET variable r and redirect to the new URL rules
if ($_GET['r']) {
switch ($_GET['r']) {
case 'site/blabla':
$url = 'blabla';
break;
[...]
}
header("Location: $url");
}
Sounds a bit dodgy but could not find an alternative
I took your solution a step further and did the following:
$app = Yii::createWebApplication($env->configWeb); //store the app
//Change the UrlFormat for urlManager to get if a get request is given instead of a path format one.
if (isset($_GET['r'])) {
Yii::app()->urlManager->setUrlFormat('get');
}
$app->run(); //run the app
Everything works perfectly now. Especially connecting with API’s where callback urls are usually in get format. I may also use my path formats for url rewritting. In a way it helps us use both get and path.
However…i feel it is not a long term solution and I will probably some day encounter a wicked bug lol.