如何为特定文件设置虚拟主机?

时间:2017-12-06 11:19:03

标签: php yii virtualhost

我正在开发Yii 1.1中的应用程序

我想将frontendbackend分开。 Doc在这里:Yii 1.1: Organize directories for applications with front-end and back-end using WebApplicationEnd behavior

我的根目录index.phpadmin.php

中有两个文件

我希望index.php通过frontend.devadmin.php backend.dev文件访问<VirtualHost *:80> ServerName frontend.dev DocumentRoot "C:\xampp\htdocs\myproject" <Directory "C:\xampp\htdocs\myproject"> AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> <VirtualHost *:80> ServerName backend.dev DocumentRoot "C:\xampp\htdocs\myproject" <Directory "C:\xampp\htdocs\myproject"> AllowOverride All Order allow,deny Allow from all RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . admin.php DirectoryIndex admin.php Require all granted </Directory> </VirtualHost> 文件。{/ 1}

代码:

http://backend.dev

如果我打开admin.php,那么这个工作正常。我的默认http://backend.dev/post/test页面工作在虚拟DirectoryIndex中设置。但是当我访问任何其他控制器和index.php之类的操作时,此URL正在访问AddDefaultCharset utf-8 Options +FollowSymLinks IndexIgnore */* RewriteEngine on # Make the backend accessible via url: http://site/backend. RewriteRule ^admin admin.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 文件。如何管理?

请帮忙

编辑:

x <- c(L1, L2)
lapply(split(x, names(x)), function(i){
    xsub <- do.call(c, unname(i))
    lapply(split(xsub, names(xsub)), function(j) do.call(rbind, unname(j)))
})

1 个答案:

答案 0 :(得分:0)

以下内容可以进入你的vhost文件

<VirtualHost *:80>
    ServerName frontend.dev
    DocumentRoot "C:\xampp\htdocs\myproject"
    <Directory "C:\xampp\htdocs\myproject">
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName backend.dev
    DocumentRoot "C:\xampp\htdocs\myproject"
    <Directory "C:\xampp\htdocs\myproject">
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

以下内容可以进入.htaccess文件。

RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^frontend.dev
RewriteRule ^(.*) index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^backend.dev
RewriteRule ^(.*) admin.php [L]

注意到 RewriteCond %{HTTP_HOST} ^frontend.devRewriteCond %{HTTP_HOST} ^backend.dev

这将正确地将域的请求转发到其各自的文件。