Htaccess为多个网站codeigniter

时间:2016-03-05 04:07:49

标签: php .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

由于

1 个答案:

答案 0 :(得分:0)

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

EG。 (apache - 我想你使用apache作为web服务器)

<VirtualHost *:80>
    ServerAdmin administrator@localhost
    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/