Answer was Updated And now work fine...
Frontend
Modify file frontend/config/main.php:
....
'components' => [
....
'request'=>[
'baseUrl'=>'/projectname',
],
'urlManager'=>[
'scriptUrl'=>'/projectname/index.php',
],
// use the following, if you want to enable speaking URL for the frontend
// 'urlManager' => [
// 'enablePrettyUrl' => true,
// 'showScriptName' => false,
// ],
],
Backend
Modify file backend/config/main.php:
....
'components' => [
....
'request'=>[
'baseUrl'=>'/projectname/admin',
],
'urlManager'=>[
'scriptUrl'=>'/projectname/admin/index.php',
],
// use the following, if you want to enable speaking URL for the backend
// 'urlManager' => [
// 'enablePrettyUrl' => true,
// 'showScriptName' => false,
// ],
],
Apache (.htaccess with mod_rewrite)
Create a file .htaccess in the project root directory (where composer.json is):
RewriteEngine On
# End the processing, if a rewrite already occurred
RewriteRule ^(frontend|backend)/web/ - [L]
# Handle the case of backend, skip ([S=1]) the following rule, if current matched
RewriteRule ^admin(/(.*))?$ backend/web/$2 [S=1]
# handle the case of frontend
RewriteRule .* frontend/web/$0
# Uncomment the following, if you want speaking URL
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^([^/]+/web)/.*$ $1/index.php
source