My config:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<alias:login|logout>' => 'site/<alias>',
],
]
My .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
my controllers: my controllers
I tested example.com/home/test, example.com/login and example.com/index.php/index/test work, but example.com/index/test 404, I have to use example.com/index.php/index/test .
any suggestion will be appreciated.
On your
htaccessfile the first rewrite condition reads:"if the file is not directly found then..."
This condition will fail and the rewrite rule won't get applied when requesting actions on
IndexControllerThe second reads: "if the directory is not directly found then..."
The first condition fails because you named one of your controllers
IndexController, it conflicts with the name ofindex.php.When you request an action on the
HomeControllerthe server first tries to find ahome.htmlorhome.phpfile, since it can't find it, it uses the rewrite rule and you get the expected result, the action on your controller runs.But, when you try to run
index/testthe server first tries to findindex.htmlorindex.php, the file is found so the rewrite rule doesn't get applied. Then the server tries to serve theindex/testfile but it can't find it and returns 404.You could rearrange your controllers, right now you have three home controllers,
SiteController,HomeControllerandIndexController, do you really need the three of them?Otherwise might be able to change your rewrite rules somehow to make it work, but I'm not sure exactly how to do it, I would think that it would be something along the lines of making the first rewrite condition more strict to make sure that only matching the exact file path stops the rewriting.
If you do modify
.htaccessmake sure afterwards that your static resources are still being served correctly.