php - How to rewrite the url in yii2 -
i have installed yii2 on system. default url localhost/projectname/backend/web/.
i want url should http://localhost/projectname frontend , http://localhost/projectname/admin backend. following 2nd answer i.e given despotbg of link yii2 htaccess - how hide frontend/web , backend/web completely getting following error
invalid call – yii\base\invalidcallexception setting read-only property: yii\web\application::request
please suggest me how can remove error can rewrite project url. working on wamp server
answer updated , work fine...
frontend
modify file frontend/config/main.php:
.... 'components' => [ .... 'request'=>[ 'baseurl'=>'/projectname', ], 'urlmanager'=>[ 'scripturl'=>'/projectname/index.php', ], // use following, if want enable speaking url 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 following, if want enable speaking url backend // 'urlmanager' => [ // 'enableprettyurl' => true, // 'showscriptname' => false, // ], ], apache (.htaccess mod_rewrite)
create file .htaccess in project root directory (where composer.json is):
rewriteengine on # end processing, if rewrite occurred rewriterule ^(frontend|backend)/web/ - [l] # handle case of backend, skip ([s=1]) following rule, if current matched rewriterule ^admin(/(.*))?$ backend/web/$2 [s=1] # handle case of frontend rewriterule .* frontend/web/$0 # uncomment following, if want speaking url #rewritecond %{request_filename} !-f #rewritecond %{request_filename} !-d #rewriterule ^([^/]+/web)/.*$ $1/index.php
Comments
Post a Comment