marvix
August 28, 2013, 8:55pm
1
Hi,
Am migrating around 100k node from Drupal 6 to Yii, all working fine, but am meeting problem with SEO urls, the best solution am thing about is to create a table which include node id, Drupal seo url.
The Yii will compare node id to the old slug, if it exist then will view the node, else check only the node id and view the content …
How ?
Thanks,
konapaz
(Konapaz)
August 29, 2013, 11:50am
2
Hi
You could use in urlManager, rules something like that
array(
'your/url/slug-a'=>'site/article/7'
'your/url/slug-b'=>'site/article/2'
'your/url/slug-c'=>'site/article/9'
'your/url/slug-d'=>'site/article/17'
'your/url/slug-e'=>'site/article/3'
)
marvix
August 29, 2013, 11:58am
3
konapaz
(Konapaz)
August 29, 2013, 12:19pm
4
You could create the accosiative array dynamically from your database.
Another solution:
check this
How to create SEO-friendly permalinks in your Yii application, including using slugs, removing index.php, forcing trailing slashes, and clean "/site/page/" URLs
marvix
August 29, 2013, 6:04pm
5
Thanks, I will check it … I knwo is can be generated with query & foreach … but its will 100k line ^^
What I need is actionBeforView(); will check the sites if its in table article or no, if no then will check in another table where new node id is reflected to the old slug …
konapaz
(Konapaz)
August 30, 2013, 10:12am
6
marvix:
Thanks, I will check it … I knwo is can be generated with query & foreach … but its will 100k line ^^
What I need is actionBeforView(); will check the sites if its in table article or no, if no then will check in another table where new node id is reflected to the old slug …
You can search in the table according to the current slug-url request,
so, it is no required to consume to much data on memory. (so check the posted article)
marvix
August 30, 2013, 11:13am
7
Then what will best way ?
moving without this I will lose search engines indexing …
redguy
(Maciej Lizewski)
August 30, 2013, 11:21am
8
I would do it like this:
store slugs in same table with content
create urlManager custom rule class that will catch only existing slugs (read: http://www.yiiframework.com/doc/guide/1.1/en/topics.url#using-custom-url-rule-classes )
put custom rule as one of first matched in urlManager
the custom rule should check if provided url matches any slug and return proper module/controller/action route to your controller and action that will get controll. Action should take the route (slug) and fetch proper record from db according to the slug…
marvix
August 30, 2013, 5:03pm
9
I will give it try … Thanks
marvix
August 30, 2013, 11:49pm
10
ended with the following … working fine, but is this best way ??
// components/UrlRule.php
class UrlRule extends CBaseUrlRule{
public $connectionID = 'db';
public function createUrl($manager,$route,$params,$ampersand){
return true;
}
public function parseUrl($manager,$request,$pathInfo,$rawPathInfo)
{
$params = explode("/", $pathInfo); // content/slugOfArticle
if($params[0] == 'content'){
$Article = Article::model()->findByAttributes(array('slug'=>$params[1]), 'status=1');
if(is_object($Article)){
Yii::app()->request->redirect(Yii::app()->getBaseUrl()."/article/".$Article->id."/".$params[1]);
}
else{
//redirect to search page
}
}
return false;
}
}
redguy
(Maciej Lizewski)
September 2, 2013, 2:28pm
11
marvix:
ended with the following … working fine, but is this best way ??
// components/UrlRule.php
class UrlRule extends CBaseUrlRule{
public $connectionID = 'db';
public function createUrl($manager,$route,$params,$ampersand){
return true;
}
public function parseUrl($manager,$request,$pathInfo,$rawPathInfo)
{
$params = explode("/", $pathInfo); // content/slugOfArticle
if($params[0] == 'content'){
$Article = Article::model()->findByAttributes(array('slug'=>$params[1]), 'status=1');
if(is_object($Article)){
Yii::app()->request->redirect(Yii::app()->getBaseUrl()."/article/".$Article->id."/".$params[1]);
}
else{
//redirect to search page
}
}
return false;
}
}
parseUrl should return route if url is matched and false otherwise so other rules can be matched, so you do not need to call "Yii::app()->request->redirect" but simply:
$Article = Article::model()->findByAttributes(array('slug'=>$params[1]), 'status=1');
if(is_object($Article)){
return "article/view";
} else {
return false;
}
this will pass controll to ArticleController::actionView() which can access Yii::app()->request->getParam( ‘slug’ ) and display the page.
using "redirect" causes request loop (sending "location" header to browser, and then another call to server)