拆除中其他的index.php和两个codeigniter网站处理子域,当一个人 [英] Removing index.php and handling subdomains of two Codeigniter sites, when one within the other
问题描述
我有两个codeigniter站点,人坐内的其它的子目录中。我需要一些帮助修改我的htaccess文件从两个删除的index.php。
I have two Codeigniter sites, one sitting within the subdirectory of the other. I need some help modifying my htaccess file to remove index.php from both.
第一个网站, http://subdomain.domain.com
保存在 /主页/网站/子域/ www / html等/
第二个, http://test.subdomain.domain.com
居 /主页/网站/子域/ www / html等/ app_staging /
这是从 /主页/网站/子域/ www / html等/
我.htacess文件:
This is my .htacess file from /home/sites/subdomain/www/html/
:
RewriteEngine On
# Rewrite the main domain
RewriteCond %{HTTP_HOST} !test.subdomain.domain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
# Rewrite the sub domain
RewriteCond %{HTTP_HOST} test.subdomain.domain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ /app_staging/index.php?/$1 [L]
这是从从第一网站中删除的index.php,一切正常存在。关于第二个网站,我可以加载默认的控制器形式 http://test.subdomain.domain.com
,但随后的页面从服务器返回404。什么是我的下一个步骤是什么?
This is removing index.php from the from the first site, everything is ok there. On the second site, I can load the default controller form http://test.subdomain.domain.com
, but subsequent pages return a 404 from the server. What are my next steps?
推荐答案
您应该把每两个的.htaccess
文件里自己的根CI文件夹。
You should put each of two .htaccess
files inside their own root CI folder.
我个人preFER限制请求的文件和/或文件夹,以prevent他们从重写规则
正在接受治疗。
Personally, I prefer restricting requested files and/or folders in order to prevent them from being treated by RewriteRule
.
所以,它位于 /主页/网站/子域/ www / html等/
的第一个文件:
So, for the first file which is located at /home/sites/subdomain/www/html/
:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico|public)
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
而对于另外一个位于 /主页/网站/子域/ www / html等/ app_staging /
:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico|public)
RewriteRule ^(.*)$ /app_staging/index.php/$1 [L]
</IfModule>
注意:您必须添加 CSS
和其他文件夹的(如公开
)的到的RewriteCond
如果你不希望他们通过重写规则
Note: You must add css
and other folders (like public
) to RewriteCond
if you don’t want them to be treated by RewriteRule
.
作为一个侧面说明::您可能需要prevent目录列表使用内部每个以下的.htaccess
文件:的
As a side-note: You might want to prevent directory listing by using the following inside each .htaccess
file:
<IfModule mod_autoindex.c>
Options -Indexes
</IfModule>
这篇关于拆除中其他的index.php和两个codeigniter网站处理子域,当一个人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!