on
Italy
- Get link
- X
- Other Apps
Options +FollowSymLinks
IndexIgnore */*
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
After that you need to configure urlManager in your config/web.php file.$config = [ //... 'components' => [ 'urlManager' => [ 'class' => 'yii\web\UrlManager', 'showScriptName' => false, 'enablePrettyUrl' => true, ], //...
/assets/ folder and the /web/assets/
folder. This is why this solution is better suited for the advanced
application template, unless you are willing to move all of your code
along with the vendors folder into a separate folder like Yii 1.x did.Options -Indexes RewriteEngine on RewriteRule ^(.*)$ web/$1 [L]
Now we have to tell Yii that our base URL has changed. We do this by configuring baseUrl for urlManager and the request component inOrder allow,deny Deny from all
config/web.php.$config = [ //... 'components' => [ 'urlManager' => [ 'class' => 'yii\web\UrlManager', 'showScriptName' => false, 'enablePrettyUrl' => true, 'baseUrl' => '/', ], 'request' => [ 'baseUrl' => '', //... ], //...If your app is in a subfolder put the name of the subfolder into the baseUrl parameter ‘baseUrl’ => ‘/app’,.
Options -Indexes
RewriteEngine on
#if the request is not to the backend, route it to /frontend/web
RewriteCond %{REQUEST_URI} !^/backend
RewriteRule ^(.*)$ /frontend/web/$1 [L]
#otherwise route the request to the backend
RewriteRule ^backend/(.*)$ backend/web/$1 [L]
These rules don’t cause a redirect loop because the request is further rewritten by the rules in the .htaccess file of the web directory.'urlManager' => [ 'class' => 'yii\web\UrlManager', 'baseUrl' => '', 'enablePrettyUrl' => true, 'showScriptName' => false, ], 'urlManagerBackend' => [ 'class' => 'yii\web\UrlManager', 'baseUrl' => '/backend', 'enablePrettyUrl' => true, 'showScriptName' => false, ],And an addition urlManagerFrontend for the backend app.
'urlManager' => [ 'class' => 'yii\web\UrlManager', 'baseUrl' => '/backend', 'enablePrettyUrl' => true, 'showScriptName' => false, ], 'urlManagerFrontend' => [ 'class' => 'yii\web\UrlManager', 'baseUrl' => '', 'enablePrettyUrl' => true, 'showScriptName' => false, ],Then you can use them like so: $frontendUrl = \Yii::$app->urlManagerFrontend->createUrl([‘site/index’]);
'urlManager' => require('urlmanager.php'),
'urlManagerBackend' => require('../../backend/config/url-manager.php'),
'urlManager' => require('urlmanager.php'),
'urlManagerFrontend' => require('../../frontend/config/url-manager.php'),
And this is how you can keep the configuration inside your url-manager.php files.'yii\web\UrlManager', 'showScriptName' => false, 'enablePrettyUrl' => true, ];
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
ServerAdmin webmaster@mytestapp DocumentRoot "C:\wamp\www\mytestapp\frontend\web" ServerName mytestapp ErrorLog "logs/mytestapp-error.log" CustomLog "logs/mytestapp-access.log" common Alias /admin "C:\wamp\www\mytestapp\backend\web" RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php AllowOverride None Order allow,deny Allow from all RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php AllowOverride None Order allow,deny Allow from all
'urlManager' => [ 'class' => 'yii\web\UrlManager', 'baseUrl' => '/', 'enablePrettyUrl' => true, 'showScriptName' => false, 'enableStrictParsing' => true, 'rules' => [ '/' => 'site/index', 'about' => 'site/about', 'contact' => 'site/contact', 'login' => 'site/login', 'logout' => 'site/logout', 'captcha' => 'site/captcha', 'signup' => 'site/signup', 'request-password-reset' => 'site/request-password-reset', 'reset-password' => 'site/reset-password', ], ],
Comments
Post a Comment