Configuring Friendly URLs for Apache on Windows

Images

In this blog post, I'll show you how to set up friendly URLs in Yii2 Framework (also known as clean URLs) for Apache on Windows. Friendly URLs make it easier for users to understand system access, and I'll guide you through configuring them for Apache on a Windows environment.
Uncomment the code in your application's frontend/config/main file. If you're working in backend/config/main.php, make the same changes there:

'urlManager' => [
'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [],
]
Add a .htaccess file to your application with the following code:

RewriteEngine on # If a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Otherwise forward it to index.php RewriteRule . index.php

Place this .htaccess file in the web folder of each application, for example, frontend/web or backend/web, depending on where you're working. This file contains rules for redirecting requests in your project.
Check the apache httpd.conf file to ensure the following line is uncommented:
LoadModule rewrite_module modules/mod_rewrite.so

Using the Config button, you can find this file in Xampp under the Apache section.
Optional:
Add rules if any changes in naming are required, etc.
You can also add suffixes if requested in the components section:

'suffix' => '.html'

By following these steps, you can configure friendly URLs for your Apache server on Windows, improving the user experience and making your system access more intuitive.
Happy coding!