2016-12-28 39 views
0

我有一個主機和一些域。我想爲每個域使用一個目錄。不幸的是我的宿主不支持虛擬主機。我在root中創建了.htaccess文件,將每個域請求重定向到它自己的目錄。使用htaccess的每個域的directores

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

    RewriteCond %{HTTP_HOST} domain1\.com [NC] 
    RewriteCond %{REQUEST_URI} ^/$ 
    RewriteRule ^(.*)$ /domain1/$1 [L] 

    RewriteCond %{HTTP_HOST} domain2\.com [NC] 
    RewriteCond %{REQUEST_URI} ^/$ 
    RewriteRule ^(.*)$ /domain2t/$1 [L] 

</IfModule> 

它工作得很好,我的網站accessabe與「http://domain1.com」地址。我嘗試使用CodeIgniter作爲我的網站框架。 因此,我將CI配置文件中的base-url配置爲「http://domain1.com/domain1/」,但它僅適用於主頁面,並且當我請求其他控制器(如「http://doamin1.com/somecontroller」)時,未找到該頁面。 另外我在站點目錄中設置.htaccess如下。

<IfModule mod_rewrite.c> 

    Options +FollowSymLinks 

    RewriteEngine On 
    RewriteBase /domain1 

    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    RewriteCond %{REQUEST_URI} ^application.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

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

</IfModule> 

我怎麼能做到這一點的工作,使瀏覽器地址欄do't顯示像 「http://doamain1.com/domain1/somecotroller」目錄(這種形式的工作)。

坦克大家。

UPDATE My routes.php。

$route['default_controller'] = 'main'; 
$route['404_override'] = ''; 
$route['translate_uri_dashes'] = FALSE; 
+0

管理您的'routes.php'。 –

+0

焦慮問題:重定向robots.txt是打破一些東西的好配方 – 2016-12-28 08:40:53

+0

@HikmatSijapati你能解釋一下嗎? – RedFlow

回答

0

我經過一些測試後得到了我需要的答案。 我換根的.htaccess這樣

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

    RewriteCond %{REQUEST_URI} !^/domain2/ 
    RewriteCond %{HTTP_HOST} ^(www\.)?domain2\. 
    RewriteRule ^(.*)$ /domain2/$1 [L] 


    RewriteCond %{REQUEST_URI} !^/domain1/ 
    RewriteCond %{HTTP_HOST} ^(www\.)?domain1\. 
    RewriteRule ^(.*)$ /domain1/$1 [L] 
</IfModule> 

而且在域目錄中每個對應的.htaccess爲遵循

<IfModule mod_rewrite.c> 

    Options +FollowSymLinks 

    RewriteEngine On 
    RewriteBase /domain1 

    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    RewriteCond %{REQUEST_URI} ^application.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

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

</IfModule> 

而且改變config.php文件基礎URL爲 「http://domain1.com/