在CodeIgniter中设置动态子域

时间:2014-09-06 09:36:24

标签: php .htaccess codeigniter virtualhost subdomain

您好我正在尝试设置我的codeigniter安装时从我的数据库中选取的动态子域名每当我尝试访问子域名时我都会收到403错误我意识到有几个问题可能会导致这个我无法确定哪一个我很抱歉,如果我问一个明显的问题,但我对此很新。

这是我的虚拟主机设置

     <VirtualHost *:80>
         DocumentRoot /var/www
        ServerName www.example.mobi
        ServerAlias example.mobi
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>

<VirtualHost *:80>
        DocumentRoot /var/www/subs
        ServerName example.mobi
        ServerAlias *.example.mobi
        <Directory /var/www/subs/>
                # Options +Indexes
                Options FollowSymLinks
                AllowOverride All
        </Directory>
</VirtualHost>

这是我的.htaccess文件

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    #this is to allow no indexes
    Options All +Indexes

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 
AddType image/x-windows-bmp bmp

这是我在尝试访问子域时看到的错误

 [error] [client x.x.s.x] Directory index forbidden by Options directive: /var/www/subs/

其他信息是我正在使用本指南 http://code.tutsplus.com/tutorials/basecamp-style-subdomains-with-codeigniter--net-16330

为子域设置我的codeigniter *当我访问域名时 “domain.mobi” 'domain'被回应,因为我已将其设置为回显子域

1 个答案:

答案 0 :(得分:0)

我发现了一个解决方案,子域虚拟主机只需要指向与主域相同的目录,然后我可以使用子域作为参数

<VirtualHost *:80>
        **DocumentRoot /var/www**
        ServerName example.mobi
        ServerAlias *.example.mobi
        <Directory /var/www/subs/>
                # Options +Indexes
                Options FollowSymLinks
                AllowOverride All
        </Directory>
</VirtualHost>