Note that there are some explanatory texts on larger screens.

plurals
  1. POYii: .htaccess and urlManager for separate backend and frontend
    primarykey
    data
    text
    <p>I'm having a hard time to configure my .htaccess and the urlManager in a Yii project to have the frontend in <a href="http://www.example.com">http://www.example.com</a> and the backend in <a href="http://www.example.com/backend">http://www.example.com/backend</a> with the following folder structure. Any help is welcome. Thanks.</p> <pre><code>/assets /backend /controllers /config main.php /models /views /common /models /protected /controllers /config main.php /models /views .htaccess backend.php index.php </code></pre> <p><strong>Solution:</strong> after the great help of @bool.dev everything it's working, so I'm adding here every needed final file. In the frontend I'm using path format for the url and hiding the index.php</p> <p>/backend/config/main.php</p> <pre><code>$backend=dirname(dirname(__FILE__)); Yii::setPathOfAlias('backend', $backend); return array( 'basePath' =&gt; $backend, 'controllerPath' =&gt; $backend.'/controllers', 'viewPath' =&gt; $backend.'/views', 'runtimePath' =&gt; $backend.'/runtime', ...); </code></pre> <p>/protected/config/main.php</p> <pre><code>'urlManager'=&gt;array( 'urlFormat'=&gt;'path', 'showScriptName'=&gt;false, 'rules'=&gt;array( '&lt;controller:\w+&gt;/&lt;id:\d+&gt;'=&gt;'&lt;controller&gt;/view', '&lt;controller:\w+&gt;/&lt;action:\w+&gt;/&lt;id:\d+&gt;'=&gt;'&lt;controller&gt;/&lt;action&gt;', '&lt;controller:\w+&gt;/&lt;action:\w+&gt;'=&gt;'&lt;controller&gt;/&lt;action&gt;', ), ), </code></pre> <p>.htaccess</p> <pre><code>Options +FollowSymLinks IndexIgnore */* &lt;IfModule mod_rewrite.c&gt; RewriteEngine on RewriteBase /yii/example/ RewriteRule backend backend\.php [T=application/x-httpd-php] # 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 &lt;/IfModule&gt; </code></pre> <p>backend.php</p> <pre><code>$yii=dirname(__FILE__).'/../../yii/framework/yii.php'; $config=dirname(__FILE__).'/backend/config/main.php'; require_once($yii); Yii::setPathOfAlias('common', dirname(__FILE__).DIRECTORY_SEPARATOR.'common'); Yii::createWebApplication($config)-&gt;run(); </code></pre> <p>index.php</p> <pre><code>$yii=dirname(__FILE__).'/../../yii/framework/yii.php'; $config=dirname(__FILE__).'/protected/config/main.php'; require_once($yii); Yii::setPathOfAlias('common', dirname(__FILE__).DIRECTORY_SEPARATOR.'common'); Yii::createWebApplication($config)-&gt;run(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload