mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
update urlnormalizer docs
This commit is contained in:
@ -519,15 +519,17 @@ contains a customized URL rule which uses `.json` as its suffix instead of the g
|
|||||||
|
|
||||||
### URL normalization <span id="url-normalization"></span>
|
### URL normalization <span id="url-normalization"></span>
|
||||||
|
|
||||||
Since version 2.0.10 [[yii\web\UrlManager|UrlManager]] uses [[yii\web\UrlNormalizer|UrlNormalizer]] for dealing
|
Since version 2.0.10 [[yii\web\UrlManager|UrlManager]] can be configured to use [[yii\web\UrlNormalizer|UrlNormalizer]] for dealing
|
||||||
with variations of the same URL with and without trailing slash. Because technically `http://example.com/path`
|
with variations of the same URL with and without trailing slash. Because technically `http://example.com/path`
|
||||||
and `http://example.com/path/` are different URLs, serving the same content for both of them can degrade SEO.
|
and `http://example.com/path/` are different URLs, serving the same content for both of them can degrade SEO.
|
||||||
By default normalizer collapses consecutive slashes, adds or removes trailing slashes depending on whether the
|
By default normalizer collapses consecutive slashes, adds or removes trailing slashes depending on whether the
|
||||||
suffix has a trailing slash or not, and redirects to normalized version of URL using [permanent redirection](https://en.wikipedia.org/wiki/HTTP_301).
|
suffix has a trailing slash or not, and redirects to the normalized version of the URL using [permanent redirection](https://en.wikipedia.org/wiki/HTTP_301).
|
||||||
Normalizer can be configured individually for URL manager and each rule - by default rule will use normalizer
|
The normalizer can be configured globally for the URL manager or individually for each rule - by default each rule will use the normalizer
|
||||||
from URL manager. You can set [[yii\web\UrlRule::$normalizer|UrlRule::$normalizer]] to `false` to disable normalization
|
from URL manager. You can set [[yii\web\UrlRule::$normalizer|UrlRule::$normalizer]] to `false` to disable normalization
|
||||||
for particular URL rule.
|
for particular URL rule.
|
||||||
|
|
||||||
|
The following shows an example configuration for the UrlNormalizer:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
[
|
[
|
||||||
'components' => [
|
'components' => [
|
||||||
|
@ -132,7 +132,7 @@ class UrlManager extends Component
|
|||||||
* If you wish to enable URL normalization, you should configure this property manually.
|
* If you wish to enable URL normalization, you should configure this property manually.
|
||||||
* For example:
|
* For example:
|
||||||
*
|
*
|
||||||
* ```
|
* ```php
|
||||||
* [
|
* [
|
||||||
* 'class' => 'yii\web\UrlNormalizer',
|
* 'class' => 'yii\web\UrlNormalizer',
|
||||||
* 'collapseSlashes' => true,
|
* 'collapseSlashes' => true,
|
||||||
|
Reference in New Issue
Block a user