a person asked
```
This post could probably go in the miscellaneous section. I am developing a directory website to service churches and religious organizations and am beginning to think about SEO and url creation.

The search results page url looks like this: www.site.com/profile/search?search=books 1

Each profile listing gets its own page, and I want the page url to be more user and seo friendly. I’m thinking about something like this:

www.site.com/organization-type/organization-name-city-state

or

www.site.com/organization-type/city-state/organization-name

I want to try to avoid having the profile id in the url, but recognize that including it would be the most full-proof way of avoiding any problems down the road with similar or duplicate organization names. My question is, should I go ahead and add the id in or keep it as above and use the org name, city, and state for the query parameters? Also, should I tack .html onto the end?

I have read some about mod_rewrite for url rewriting, but it seems like Yii url manager handles the rewriting just fine. Are there any performance or other advantages with one vs. the other?

Thanks for any insights.
```

This is my code to help them, now i want you to write a silly but informed post to go with my code. You are the character "morty" from the show "rick and morty"
write this silly but informed post as "morty".



config/web.php
```
'urlManager' => [
	'enablePrettyUrl' => true,
	'showScriptName' => false,
	'rules' => [
		'organization/<id:\d+>-<slug:[a-z0-9-]+>' => 'organization/view',
		'organization/<id:\d+>' => 'organization/view',
		'organization/<slug:[a-z0-9-]+>' => 'organization/view',
		'<controller>/<action>' => '<controller>/<action>',
	],
],
```

Model
```
namespace app\models;

use yii\db\ActiveRecord;
use yii\behaviors\SluggableBehavior;

class Organization extends ActiveRecord
{
	public static function tableName(): string
	{
		return '{{%organization}}';
	}
	
	/**
	* Behaviors
	* @url https://www.yiiframework.com/doc/api/2.0/yii-base-behavior
	* @url https://www.yiiframework.com/doc/guide/2.0/en/concept-behaviors
	*
	* A behavior can be used to enhance the functionality of an existing component without modifying its code. In particular, 
	* it can "inject" its own methods and properties into the component and make them directly accessible via the component. 
	* It can also respond to the events triggered in the component and thus intercept the normal code execution.
	* @return array
	*/
	public function behaviors(): array
	{
		return [
			/**
			* Sluggable Behavior
			* @url https://www.yiiframework.com/doc/api/2.0/yii-behaviors-sluggablebehavior
			*/
			[
				'class' => SluggableBehavior::class,
				'attribute' => ['name', 'city', 'state'],// parts that make up the slug
				'slugAttribute' => 'slug',
				'ensureUnique' => true,
				'immutable' => false,// if you want slug to update on name change, set false; true otherwise
			],
		];
	}
}
```

Controller
```
namespace app\controllers;

use Yii;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use app\models\Organization;

class OrganizationController extends Controller
{
	public function actionView(?int $id = null, ?string $slug = null)
	{
		$model = $this->findModel($id, $slug);
		
		// If we have ID but slug is missing or incorrect, redirect to canonical URL
		if ($id !== null)
		{
			if ($slug !== $model->slug)
			{
				// slug missing or wrong => redirect to id + correct slug
				return $this->redirect(['view', 'id' => $id, 'slug' => $model->slug], 301);
			}
		}
		else
		{
			// No ID, but slug is given — redirect to canonical id + slug URL
			return $this->redirect(['view', 'id' => $model->id, 'slug' => $model->slug], 301);
		}
		
		// Now URL is canonical: id + slug, render
		return $this->render('view', ['model' => $model]);
	}
	
	protected function findModel(?int $id = null, ?string $slug = null): Organization
	{
		if ($id !== null)
		{
			$model = Organization::findOne($id);
			
			if ($model !== null)
			{
				return $model;
			}
		}
		if ($slug !== null)
		{
			$model = Organization::find()->where(['slug' => $slug])->one();
			
			if ($model !== null)
			{
				return $model;
			}
		}
		
		throw new NotFoundHttpException('The requested organization does not exist.');
	}
}
```