2

I am trying to set-up Yii2 to use pretty URL. In order to do so, I configured Yii2 and used the rewrite module of apache to make sure that we always enter by the entry point which is index.php

I made the following modification in the .htaccess file contained in the yii-application/frontend/web/ folder - folder that contains index.php (advanced yii2 template). For those modifications, I followed instructions found on various forums.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

I have also made the following changes in the configuration of yii2 in order to activate pretty URL

$config = [
'components' => [
    'urlManager' => [
        'showScriptName' => false,
        'enablePrettyUrl' => true,
        'rules' => array(
            '<controller:\w+>/<id:\d+>' => '<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
        ),
    ],
],
];

Note that Yii2 was working well before I made those changes.

Now if I try to connect using one of the following URL (like before modification), I see the landing page. The navigation will not work, I will always see the landing page.

http://localhost/frontend/
http://localhost/frontend/index.php
http://localhost/frontend/index.php?r=site/about-us
http://localhost/frontend/index.php?r=site/faq

If I try to connect using of the URLs below (as I should once pretty URL is configured properly), my brower displays an error message.

http://localhost/frontend/site/faq
http://localhost/frontend/site/account
http://localhost/frontend/site/index

Error message:

Not Found
The requested URL /web/yii-application/frontend/web/index.php was not found on this server.
Apache/2.4.9 (Win32) PHP/5.5.12 Server at localhost Port 80

However, it looks like the path is correct. The index.php file is actually in the folder C:\web\yii-application\frontend\web\index.php How come my browser does not find the file?

Thanks for your help

1 Answer 1

1

From all your requests you are missing the web folder.

All your URLs should be

http://localhost/frontend/web/
http://localhost/frontend/web/index.php
http://localhost/frontend/web/index.php?r=site/about-us
http://localhost/frontend/web/index.php?r=site/faq

http://localhost/frontend/web/site/faq
http://localhost/frontend/web/site/account
http://localhost/frontend/web/site/index

Unless you set up a folder redirection but considering how you have things set up I seriously doubt that.

Sign up to request clarification or add additional context in comments.

2 Comments

No mistake there. I do not need the "/web" before or after using the rewriting. localhost/frontend locally points to c:\web\yii-application\frontend\web\
You might be doing it wrong then. /web/yii-application/frontend/web/index.php, it is trying to access index.php inside a strange "web" folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.