how to enable pretty url in yii2

To enable pretty URLs in Yii2, you need to follow these steps:

  1. Open the config/web.php file in your Yii2 project.
  2. Locate the components array within the return statement.
  3. Add the following code to the components array:
'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => [
        // Add your URL rules here
    ],
],
  1. 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.