1

This might be a dumb question, but I can't do it. I've searched about this for a long time but still haven't found anything.

I'm using Yii2 advanced template and I'd like to remove the "frontend/web/" and "index.php" so it will have a pretty URL, for example: www.mywebsite.com/signin instead of www.mywebsite.com/frontend/web/index.php?r=site/signin

I have this htaccess in root folder:

Options -Indexes

<IfModule mod_rewrite.c> 
  RewriteEngine on

  RewriteCond %{REQUEST_URI} !^public
  RewriteRule ^(.*)$ frontend/web/$1 [L] 
</IfModule>

# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>

# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]

And also this htacccess in frontend 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

Options -Indexes

Lastly, here is the config for UrlManager:

use \yii\web\Request;
$baseUrl = str_replace('/frontend/web', '', (new Request)->getBaseUrl());

return [
    'urlManager' => [
        'baseUrl' => $baseUrl,
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            'signin' => 'site/signin',
            '<controller:\w+>/<id:\d+>' => '<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
        ]
    ]
]

"Signin" is an action in SiteController.php in frontend folder. How can I access it? I tried www.mywebsite.com/signin, www.mywebsite.com/site/signin, but failed. Is there something wrong with the settings in htaccess or the config? Any help would be appreciated.

Henry Gunawan
  • 922
  • 3
  • 18
  • 38
  • Refer my answer http://stackoverflow.com/questions/38426427/yii2-access-to-higher-level-folder – vishuB Aug 03 '16 at 12:49

0 Answers0