Yii 1.1: seourlmanager

SEO friendly URLs
12 followers

Development of seoUrlManager has been DISCONTINUED. There will be no future updates, bug fixes or support.

seoUrlManager is a Yii Framework Extension that extends CUrlManager to make your web application URLs more SEO friendly.

Features

  • No duplicate content with help of 301 redirects
    • Add/strip www in URL
    • Remove entry script from URL
    • Add trailing slash to URL
    • Remove multiple slashes in URL
    • Remove Query String from URL
  • Create unique URLs
  • Automatically configure certain settings of urlManager

Requirements

  • Yii 1.1.8+ (might work on lower versions, not tested)

Installation

1: Download the latest version from here
2: Extract it and copy the seoUrlManager folder into your Yii extensions folder
3: In your main Yii configuration file define the class for the urlManager Component

<?php
return array(
        ........
        'components'=>array(
                'urlManager'=>array(
                        'class'=>'ext.seoUrlManager.components.ExtSeoUrlManager',
                ),
        ),
);

4: Create a file called .htaccess in the same folder as your Yii Entry Script file (index.php) with following content. Adjust filenames as necessary.

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

Update

If you are updating to a new version, delete the seoUrlManager folder inside your extensions folder and repeat steps 1-2 from the installation instructions above.

Configuration

You can basically use the same configuration options that are available in CUrlManager, but most of them will be overwritten or extended by seoUrlManager (useStrictParsing, urlFormat, showScriptName, urlSuffix, caseSensitive, appendParams). Following is a list with new settings that are added by seoUrlManager.

  • wwwMode
    • Define if www should be stripped or added to URL. Deactivate by setting it to false.
    • Available options: 'add', 'strip', false
    • Default: 'add'

Please note that either the rules or the urlRuleClass setting is required for seoUrlManager to work. More info on these two settings can be found here. If you plan on using Gii you will need to add rules as defined here.

Configuration sample:

<?php
return array(
        ........
        'components'=>array(
                'urlManager'=>array(
                        'class'=>'ext.seoUrlManager.components.ExtSeoUrlManager',
                        'cacheID'=>'cache',
                        'rules'=>array(
                                ''=>'site/index',
                                'test'=>'site/test',
                        ),
                        'wwwMode'=>'strip',
                ),
        ),
);

Usage

seoUrlManager does not need any user interaction since everything runs automatically. It is actually a more restricted version of the standard urlManager so expect it not to have certain flexibility since its goal is to create unique and simple URLs in a specific format.

Changelog

  • 1.0.1
    • Fail silently if URL cannot be parsed
    • Adjust error messages and logging parameters
    • Adjust property/method visibility to allow class extensions
  • 1.0
    • Initial release

Total 4 comments

#4887 report it
limitless at 2011/08/25 09:48am
Re: Query String

it kinda defeats the purpose of the extension to globally allow query string... so i decided to not implement anything in that direction as of right now... maybe later... right now i will keep that up to individual needs so that if you need query strings you should be able to easily extend ExtSeoUrlManager class on your own...

if u come up with a good idea where query strings are not globally activated let me know please...

#4882 report it
zeckon at 2011/08/24 06:23pm
Query String

Hello again, I considered converting ajax gets to posts but there are many 3rd party plugins so it isn't feasible for us, and also there will be extra future work for new plug-ins.

Actually my current solution is, adding $urlParts['query'] to _connectUrlParts return if query is not empty. It seems to work for me but not sure if it's a complete solution.

#4881 report it
limitless at 2011/08/24 03:29pm
re: Removing Query String

Hey zeckon

Thanks for your feedback...

you might be right... one possible solution is to use POST instead of GET. you can define that with the type option in jquery's ajax method.

if you have a sexy solution that comes to your mind just let me know and i will see if i can implement it...

#4880 report it
zeckon at 2011/08/24 01:40pm
Removing Query String

Thanks for the extension, however I encountered a problem, I think removing query string breaks jquery ajax gets.

Leave a comment

Please to leave your comment.

Create extension