I have started learning yii2 and I tried to do pretty URL stuff but failed. What I did:-
in config/web.php (I have edited below):
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Hide index.php
'showScriptName' => false,
// Use pretty URLs
'enablePrettyUrl' => true,
'rules' => [
],
*** Then I created a .htaccess
file and put it on the root (it has the below 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
Also I had opened apache2.conf file and changed like this:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All <! -- instead of none -->
Require all granted
</Directory>
Also I checked the changes through the command:
grep -R AllowOverride /etc/apache2
And it shows like below:
/etc/apache2/apache2.conf: AllowOverride All <!-- It is showing that done -->
Now:
when I access my page through:
http://localhost/yii2/web/
it's opened and when I hover over any link on the page, it shows me something like this: http://localhost/yii2/web/site/about (which shows that pretty URLs are made)
But these URLs are not working (says 404 found)
I tried below code links answers also but didn't work for me:
<Directory "/var/www/html"> AllowOverride All </Directory>
<br> in my default website configuration in apache ie: the file "/etc/apache2/sites-available/000-default.conf" <br> ps: if using advanced template you should add the .htaccess file in the frontend web directory and the backend's <br> hope this is helpful – Gunzburg