how to enable pretty url in yii2
To enable pretty URLs in Yii2, you need to follow these steps:
- Open the
config/web.php
file in your Yii2 project. - Locate the
components
array within thereturn
statement. - Add the following code to the
components
array:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
// Add your URL rules here
],
],
- Save the file.
By adding this code, you are configuring the urlManager
component to enable pretty URLs. The enablePrettyUrl
option allows Yii2 to generate clean and user-friendly URLs. The showScriptName
option removes the index.php
part from the URL.
Remember to add your custom URL rules within the 'rules'
array if you have any specific routing requirements.
That's it! Pretty URLs should now be enabled in your Yii2 application.