Home Page » Url Management » How to setup urlManager to make url more friendly for SEO
0
Votes
How to setup urlManager to make url more friendly for SEO
Hello Everyone!,
How to setup urlManager to make url more friendly as like as http://yiianswers.com or http://yiiframework.com or http://mydomain.com/post/up-coming-calendar/year-2012
Please help me asap.
Thanks in Advance
By Hrishita in Url Management · Asked 608 days 21 hours 42 mins ago
Questions: 1 Accepted: 0 ( 0% ) | Reputation: 0
Possibly related Questions
-
Controller – Friendly URL rules
September 28, 2011 By olivercera 4 Answers
TAGS
actioncreate ( x 2 )ACTIVERECORD ( x 4 )AJAX ( x 10 )ajaxSubmitButton ( x 4 )AR ( x 2 )cactivedataprovider ( x 2 )CActiveForm ( x 2 )cactiverecord ( x 2 )CGridView ( x 14 )CJuiAutoComplete ( x 3 )CJuiDialog ( x 8 )CListView ( x 8 )controller ( x 7 )Css ( x 2 )CStarRating ( x 2 )CTreeView ( x 2 )database ( x 5 )dialog ( x 2 )dropdownlist ( x 3 )EGMaps ( x 3 )extension ( x 3 )file ( x 2 )form ( x 6 )Giix ( x 2 )gridview ( x 2 )html ( x 2 )javascript ( x 3 )many_many ( x 4 )merge ( x 2 )model ( x 4 )Modules ( x 3 )multilanguage ( x 2 )php ( x 2 )redirect ( x 4 )Registration ( x 3 )relations ( x 5 )renderPartial ( x 8 )session ( x 2 )sorting ( x 3 )sql ( x 4 )url ( x 3 )urlManager ( x 3 )validation ( x 3 )yii ( x 11 )YiiAnswers Site ( x 4 )This website counts Questions and 429 Answers by 17410 registered users.

1. Open file config/main.php
2. Find and update line “urlManager” according to your needs.
As an example
When you type
http://www.youdomain.com/whatever
you want to show what’s in your (controller => site) (action =>index)
http://www.youdomain.com/site/create/index.php
You will have to update code to
// uncomment the following to enable URLs in path-format 'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName' => false, 'rules'=>array( 'whatever' => array('site/create'), '/'=>'/view', '//'=>'/', '/'=>'/', //'~'site/page' ),Also you will have to update file .htaccess
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.phpFor more information please look
here,
here
and here
By tuolden · 608 days 20 hours 56 mins ago
Questions: 25 Accepted: 0 ( 0% ) | Reputation: 0
Thanks tuolden, I did all that things, please take a look below: [code] 'urlManager' => array( 'urlFormat' => 'path', 'rules' => array( array('class' => 'ext.sitemapgenerator.SGUrlRule'), '/about' => '/site/page/view/about', '/sitemap' => '/site/sitemap', '/sitemap.xml' => '/site/sitemapxml', '/press-and-media' => '/site/pressandmedia', '/privacy-and-policy' => '/site/privacyandpolicy', // '/blog' => 'wordpress', '/' => '/view', '//' => '/', '/' => '/', ), 'showScriptName' => false, ), [/code] And .htaccess as you written. As you written above, are you sure will handle like below url http://yiianswers.com/url-management/how-to-setup-urlmanager-to-make-url-more-friendly-for-seo/ In above URL my config tell url-management is controller and how-to-setup-urlmanager-* tells this is action. But problem is function actionHow-to-setup-urlmanager(){} this is not valid. So, please help me again Thanks
By Hrishita · 608 days 6 hours 59 mins ago
Thanks tuolden, I did all that things, please take a look below: 'urlManager' => array( 'urlFormat' => 'path', 'rules' => array( array('class' => 'ext.sitemapgenerator.SGUrlRule'), '/about' => '/site/page/view/about', '/sitemap' => '/site/sitemap', '/sitemap.xml' => '/site/sitemapxml', '/press-and-media' => '/site/pressandmedia', '/privacy-and-policy' => '/site/privacyandpolicy', // '/blog' => 'wordpress', '/' => '/view', '//' => '/', '/' => '/', ), 'showScriptName' => false, ), And .htaccess as you written. As you written above, are you sure will handle like below url http://yiianswers.com/url-management/how-to-setup-urlmanager-to-make-url-more-friendly-for-seo/ In above URL my config tell url-management is controller and how-to-setup-urlmanager-* tells this is action. But problem is function actionHow-to-setup-urlmanager(){} this is not valid. So, please help me again Thanks
By Hrishita · 608 days 6 hours 57 mins ago
Hello Hrishita
1st – try to post an answer and use the codeblock button when submitting code. Easier to read.
2nd – I think the problem now is not with urlManager but with controller definition.
Another example, using your example URL
Suppose you want the following link to work.
http://yourdomain.com/url-management/how-to-setup-urlmanager-to-make-url-more-friendly-for-seo/
In your controller.
class SiteController extends Controller { ... // accessRules must be set public function actionWhatever() { ... } }In config/main.php
// uncomment the following to enable URLs in path-format 'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName' => false, 'rules'=>array( '/url-management/how-to-setup-urlmanager-to-make-url-more-friendly-for-seo/' => array('site/whatever'), '/'=>'/view', '//'=>'/', '/'=>'/', //'~'site/page' ),This is “hardcoded” way of doing it.
If you want to create URL based on ID’s or Name’s you will need regular expression.
Please look over previous links.
Hope this helps
By tuolden · 607 days 20 hours 37 mins ago
Questions: 25 Accepted: 0 ( 0% ) | Reputation: 0
The default urlManager that is commented works fine for me simple by uncommenting it…
// uncomment the following to enable URLs in path-format 'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName'=>false, 'rules'=>array( '<controller:\w+>/<id:\d+>'=>'<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', ), ),Then I just use the following .htaccess in the same directory as my index.php file:
RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]If I use Yii in a subdirectory path like http://www.myserver.com/myapp/ I change my .htaccess as follows:
RewriteEngine On RewriteBase /myapp/ #Must reflect the Document Root relative path! RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]One last item, please also check and make sure that mod_rewrite is enabled in apache by uncommenting the line:
By ddreggors · 607 days 18 hours 6 mins ago
Questions: 0 Accepted: 0 ( 0% ) | Reputation: 0
Ahh yes, one more thing…
Note that my urlManager has the line:
That will make sure your auto-generated links (CHtml::link or zii.widgets.CMenu) do not have index.php in them. This will not work without the .htaccess file. The reason is that the .htaccess file rewrites the url to point to index.php/$1 so that Yii actually gets the request properly. You will not see the index.php in the url at any time though.
By ddreggors · 607 days 18 hours ago
Questions: 0 Accepted: 0 ( 0% ) | Reputation: 0