I am facing an issue in my YII2 project. I am adding the URL suffix in the rules and it is throwing me 404 error. I don't know why i am facing this issue. Let me share my url Manager rule
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'suffix' => '.html',
'rules' => [
'login'=>'userportal/default/login',
],
],
If i remove suffix or comment that line my web application will run fine. But if with this code the web application throws 404 error.
I am using xampp on my localhost with apache server.
The .htaccess in web folder looks like this
RewriteEngine on
RewriteRule ^index.php/ - [L,R=404]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
Do let me know what is wrong?
Thanks
Try this:(Working solution)
Basic app
config/web.php
app/web/.htaccess
To access your action you simply use
login.htmland it will rendersite/loginaction. To be able to properly render your url, useUrlhelper like this:it will generate proper link using the desired extension:
Also here is the documentation with more tricks on how to manage url's in yii2 application.Routing and URL Creation