I started out with the Yii2 “advanced” template and I finally got pretty urls to work, along with hiding “index.php”. It was pretty frustrating because there are a lot of “answers” on the web to this and none of them worked for me. Then I read “Yii2 Quickstart Guide” by JB McKee and the clear example worked for me. So now I’ve installed the “basic” template, assuming that I could simply copy my “.htaccess” commands from the other template, along with my “config” parms.
Nope. I cannot get the “basic” template to hide the “index.php” file. If I set ‘showScriptName’ => false, then none of the menu items work except for the “My Company” one, whose URL looks like ‘localhost/yiibasic’. The “Home” one doesn’t work, I guess because it’s using ‘localhost/yiibasic/index’ – I don’t know.
If I set ‘showScriptName’ => true or comment it out, then everything works fine – except I have to look at “index.php” in every URL.
Here are the htaccess options (the recommended ones) that I have:
RewriteEngine On
RewriteBase /yii_basic/ (Note that yii_basic is my real dir name and I have aliased it in my httpd.conf)
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
… and here are the config/web.php parms I have (again, the ones I saw recommended)
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<alias:\w+>' => 'site/<alias>',
],
],
This is all on my localhost. I am not going to be able to edit Apache stuff on my hosting service but I can edit or create another htaccess.
I’ve seen so many strange alternatives offered on the web (stackoverflow, etc…) but I couldn’t get them to work and since my advanced template works with these, I figured my basic one should.
So, as I mentioned, this exact same set of rules and parms works just fine in the advanced template. I’d certainly appreciate any ideas on what I’m doing wrong and how the basic template might differ from the advanced in ways that may cause this. Thanks