0

Using yii2 to develop web service. The results always return 404 not found if pretty url is enable. I suspect the htaccess or httpd.conf is not working.

Expected route: http://localhost:63342/myproject/admin/api/totalviews

If the pretty url is disable, http://localhost:63342/myproject/admin/index.php?r=api/totalviews is working.

Here is the web.php.

'id' => 'basic',
'basePath' => dirname(__DIR__),
'homeUrl' => 'http://localhost:63342/myproject/admin/', 
'bootstrap' => ['log'],
'defaultRoute' => 'login/index',
'components' => [
    'twiliosms' => [
        'class' => 'app\components\TwilioSms',
    ],
    'request' => [
        'cookieValidationKey' => 'abc123',
        'parsers' => [
            'application/json' => 'yii\web\JsonParser',
        ]
    ],
    'urlManager' =>
        [
            'class' => 'yii\web\UrlManager',
            'showScriptName' => false,
            'enablePrettyUrl' => true,
            'rules' => [
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
                '<view:(about)>' => 'login/page',
                '<action:(index)>' => 'login/<action>',
                '<action:(forgotpassword)>' => 'login/forgotpassword<action>',
                '<alias:dashboard|forgotpassword>' => 'login/<alias>',
            ],
        ]

This is .htaccess file in root directory.

`<IfModule mod_autoindex.c>
  Options -Indexes
</IfModule>

<IfModule mod_rewrite.c>
  RewriteCond %{SCRIPT_FILENAME} -d
  RewriteCond %{SCRIPT_FILENAME} -f
  RewriteRule "(^|/)\." - [F]
</IfModule>

<FilesMatch "(\.(bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)|~)$">
  Order allow,deny
  Deny from all
  Satisfy All
</FilesMatch>

<IfModule php5_module>
  php_value session.cookie_httponly true
</IfModule>

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

This is admin.\htaccess in admin folder.

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

I am using wamp server and this is httpd-vhost.conf file.

<VirtualHost *:8080>
ServerName localhost
DocumentRoot c:/wamp64/www 
<Directory  "c:/wamp64/www">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require all granted
</Directory>

Any idea?

JohnnyCc
  • 525
  • 1
  • 8
  • 23

0 Answers0