Skip to content

Instantly share code, notes, and snippets.

@ptrnov
Created May 23, 2016 11:13
Show Gist options
  • Select an option

  • Save ptrnov/43cc39426cda1bc6c4c203753ce8a143 to your computer and use it in GitHub Desktop.

Select an option

Save ptrnov/43cc39426cda1bc6c4c203753ce8a143 to your computer and use it in GitHub Desktop.
[1]=== .htaccess ===> public_html ====
#Options +FollowSymlinks
RewriteEngine On
# deal with admin first
#RewriteCond %{REQUEST_URI} ^/(admin)
#RewriteRule ^admin/assets/(.*)$ backend/web/assets/$1 [L]
#RewriteRule ^admin/css/(.*)$ backend/web/css/$1 [L]
#RewriteCond %{REQUEST_URI} !^/backend/web/(assets|css)/
#RewriteCond %{REQUEST_URI} ^/(admin)
#RewriteRule ^.*$ backend/web/index.php [L]
RewriteCond %{REQUEST_URI} ^/(assets|css)
RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
#RewriteCond %{REQUEST_URI} !^(frontend|backend)/web/(assets|css)/
RewriteCond %{REQUEST_URI} !^advanced/(frontend)/web/(assets|css)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$frontend/web/index.php [NC,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
#RewriteRule ^.*$ - [NC,L]
#RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^.*$ frontend/web/index.php [NC,L]
[2]=== common/components ===> create class Request
<?php
namespace common\components;
class Request extends \yii\web\Request {
public $web;
public $adminUrl;
public function getBaseUrl(){
return str_replace($this->web, "", parent::getBaseUrl()) . $this->adminUrl;
}
/*
If you don't have this function, the admin site will 404 if you leave off
the trailing slash.
E.g.:
Wouldn't work:
site.com/admin
Would work:
site.com/admin/
Using this function, both will work.
*/
public function resolvePathInfo(){
if($this->getUrl() === $this->adminUrl){
return "";
}else{
return parent::resolvePathInfo();
}
}
[3]=== Declaration componen ===> common/config/main.php
<?php
return [
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'request'=>[
'class' => 'common\components\Request',
'web'=> '/frontend/web'
],
],
];
@jagwara
Copy link

jagwara commented Sep 18, 2017

My question is if I keep .htaccess file out of the project folder (on htdocs / on public_html), how can i access other project without .htaccess file on them. Whenever i want to access other project, it show me "Object Not found". If i delete the .htaccess file from htdocs / public_html it works fine. But condition is I need .htaccess file on the htdocs / public_html and also i need others project without .htdocs on them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment