How can I have a custom UrlRoute to be triggered only for some section of the website?

I was reading section 8. Using Custom URL Rule Classes from here

[color=#454545][font=Arial, Helvetica, sans-serif]We would write a CUrlRule that matched a path we want to redirect in the parseUrl method. if we found one, the createUrl would be called–we could look up the redirect destination in the database or call any other custom functions and then pass the user on. We want to manage the destinations in a database table.[/font][/color][color=#454545][font=Arial, Helvetica, sans-serif]

[/font][/color][color=#454545][font=Arial, Helvetica, sans-serif]In this case we would modify the configuration, write a UrlRule component, and have a model interface to the db. Every URL passed through the application would evaluate the match rule, creating a (immeasurably?) small performance cycle. [/font][/color][color=#454545][font=Arial, Helvetica, sans-serif]

[/font][/color][color=#454545][font=Arial, Helvetica, sans-serif]So is this correct? Does a custom URL Rule Class triggered each time for every URL? What shall we do in order to be called just once for the URLs we want to, and not for the other urls of the site?[/font][/color]


a custom UrlRule is not exactly triggered each time for every URL. But if you place your own ruleRule on top of configured rules, than this urlRule is triggered every time ;). The UrlManager goes url rules down until “he” finds a matching rule. So the position of your urlRule in the configuration is important. Furthermore you have the possibility to return false in your own urlRule::parseurl method before any SQL was executed. You could do this by matching against a regular expression (for example).

// configuration


	array (

		'class' => 'application.components.YourUrlRule'


	// default routes






// your urlRule in application\components\

class YourUrlRule extends CBaseUrlRule


	public function parseUrl ($manager, $request, $pathInfo, $rawPathInfo)


		if (!preg_match ("/some Pattern/", $pathInfo))


			// go on with default rules

			return false;


		// your database stuff here

		// ...

		// redirect not found?

		if (!$redirectFound)

			return false;


		// return found redirect

		return 'some/redirect';


Regards Robert

Is there a way I can limit per a subdomain?

Is there a way I can limit per a controller?