In my Yii2 project,I have rewrite the URL from myproject/backend/web to myproject/admin and from myproject/frontend/web to myproject/.
Frontend works fine but in backend the common/web/css/ and common/web/js/ is not loading and I this all these redirect to frontend and gives 404 page not found error.
I have checked the path of css and js and it's correct as below : myproject/common/web/css/style.css. all css and js loaded with correct paths but it redirects to some other place.
I have used below code for rewriting :
I have added this .htaccess :
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
I have added this two lines in backend/config/main.php :
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'scriptUrl'=> ($_SERVER['HTTP_HOST'] == "localhost") ? '/chiefsRS/admin' : '/admin',
'rules' => [
'login'=>'site/login',
'dashboard'=>'site/index',
]
],
'request' => [
'baseUrl'=>($_SERVER['HTTP_HOST'] == "localhost") ? '/myproject/admin' : '/admin',
],
I have added this two lines in frontend/config/main.php :
'request' => [
'baseUrl'=> ($_SERVER['HTTP_HOST'] == "localhost") ? '/myproject' : '',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'scriptUrl'=>($_SERVER['HTTP_HOST'] == "localhost") ? '/myproject' : '',
'rules' => [
'home'=>'site/index',
]
]
In my local server some css from common loaded and some gives 404 error. In live server all css and js from common/web gives me 404 page not found error. And error page has navbar of frontend so i think all css and js are redirecting to fronted.