不同的URL指向不同的目录

时间:2015-02-19 20:36:15

标签: apache mod-rewrite laravel laravel-4

如果我选择http://example.com,则指向/var/www/html

现在我需要的是,如果我选择http://example.com/dashboard,那么它会指向/var/www/example/public。或者如果这不可能,那么/var/www/html/example/public也可以。

我再次需要,如果我选择http://wildcardsubdomain.example.com/,那么它也会指向/var/www/example/public。或者如果这不可能,那么/var/www/html/example/public也可以。

我怎么能这样做?

我试过这个,但/dashboard无法正常工作:

ServerName example.com
# Listen for virtual host requests on all IP addresses
UseCanonicalName Off
#dynamic subdomain provisioning
<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
    #WORKING
    ServerName user.example.com
    ServerAlias *.example.com
    DocumentRoot /var/www/example/public
</VirtualHost>
<VirtualHost *:80>
    #NOT WORKING
    ServerName www.example.com/dashboard
    ServerAlias *.example.com/dashboard
    DocumentRoot /var/www/example/public
</VirtualHost>
<Directory /var/www/html/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

1 个答案:

答案 0 :(得分:0)

对于dashboard我可以使用Alias Directive

解决这个问题
<VirtualHost *:80>

    DocumentRoot /var/www/html

    Alias /dashboard /var/www/example/public
    <Directory /var/www/example/public>
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>