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 have created a .htaccess
file and put it on root (it has 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:
it's opened and when I hover on any link of the page,it showed me something like this: http://localhost/yii2/web/site/about (which shows that pretty URL's maid)
But these URL's are not working (says 404 found)
I have tried below posts code also, but didn't worked for me:
however i used only one .htaccess inside my yii application web root and added ```
in my default website configuration in apache ie: the file "/etc/apache2/sites-available/000-default.conf"
ps: if using advanced template you should add the .htaccess file in the frontend web directory and the backend's
hope this is helpful – leila Jul 23 '17 at 01:10