2016-03-05 54 views
0

我有一个网站与子域。Htaccess为多个网站codeigniter

我试图搜索谷歌,但仍然没有与我的项目合作。

我的结构文件夹是:

-public_html 
--subdomain_folder (this is codeigniter) 
---htaccess_for_subdomain 
--domain_folder (this is my own projects website) 
---htaccess_for_domain 
--htaccess_for_root 
下面

是我的htaccess代码:

htaccess_for_root(的public_html)

RewriteEngine on 

RewriteCond %{HTTP_HOST} ^(www.)?domain.go.id$ 

RewriteRule ^(.*)/^(.*)/files/source/(.*)\.(gif|jpg|png|jpeg|css|js|swf|JPG)$ files/source/$2.$3 [QSA] 

RewriteCond %{REQUEST_URI} !^/domain_folder/ 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^(.*)$ /domain_folder/$1 

# Change yourdomain.com to be your primary domain again. 
# Change 'subfolder' to be the folder you will use for your primary domain 
# followed by/then the main file for your site, index.php, index.html, etc. 

RewriteCond %{HTTP_HOST} ^(www.)?domain.go.id$ 
RewriteRule ^(/)?$ domain_folder/index.php [L] 

****这是我的htaccess_for_domain *** *

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^(.*)/files/source/(.*)\.(gif|jpg|png|jpeg|css|js|swf|JPG)$ files/source/$2.$3 [QSA] 

RewriteBase /web/ 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /domain_folder/index.php [L] 

这htaccess_for_subdomain

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteRule ^index.php/(.*)$ /$1 [R=302,L] 

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond $1 !^(index\.php|images|robots\.txt) 
    RewriteRule ^(.*)$ index.php?/$1 [L] 

</IfModule> 

当我进入我的子域(www.sub.domain.go.id)它总是不正确重定向。

,我想的是,当我访问www.domain.go.id它会重定向到domain_folder,当我访问www.sub.domain.go.id,它会重定向到subdomain_folder

感谢

回答

0

我认为最适合您的解决方案是使用虚拟主机,并将每个域/子域的documentRoot设置为指向其特定的文件夹。

例如, (apache - 我想你使用apache作为web服务器)

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName www.sub.domain.go.id 
    DocumentRoot /path/to/your/project/public_html/subdomain_folder 
    <Directory /path/to/your/project/public_html/subdomain_folder/> 
      Options Indexes FollowSymLinks MultiViews 
      AllowOverride All 
      Require all granted 
      RewriteEngine on 
      RewriteCond %{HTTP_HOST} ^www.sub 
      RewriteCond $1 !^(index\.php|images|robots\.txt) 
      RewriteRule ^(.*)$ /index.php/$1 [L] 
    </Directory> 
</VirtualHost> 

对你的域指向domain_folder做同样的事情。 你可以在这个链接中找到更多关于apache的虚拟主机的信息 https://httpd.apache.org/docs/2.4/vhosts/