2016-03-05 97 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/