Eu quero dividir meu IC em vários aplicativos. Eu devo dizer que ele está dentro de uma pasta chamada app na raiz / var / www / app /. Primeiro eu tentei esta configuração:
/system/
/application/
/app1/
/app2/
app1.php
app2.php
.htaccess
Mas eu não consegui meu htaccess apontar corretamente. Portanto, fui em frente com isso:
/system/
/app1/
.htaccess
/application/
index.php
/app2/
.htaccess
/application/
index.php
E agora funciona bem com urls: mysite.com/app/app1/index.php/welcome - mas eu gostaria de esconder index.php da URL. Portanto, meu .htaccess é assim:
RewriteEngine on
RewriteCond $1 !^(index.php|gfx|css|js|robots.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
No entanto, não está funcionando, fico com 404 ao tentarpara acessar mysite.com/app/app1/welcome. Alguém poderia esclarecer o que está errado com o meu .htaccess? Eu tenho outro .htaccess na raiz e irá executar alguns wordpress de lá, mas isso afetaria minha pasta / app onde o CI é executado? Muito obrigado!
Respostas:
2 para resposta № 1Tente adicionar este em cada pasta (de http://codeigniter.com/wiki/mod_rewrite):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#"system" can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn"t in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename "application" to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn"t true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don"t have mod_rewrite installed, all 404"s
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
0 para resposta № 2
Funciona depois que você adiciona uma diretiva RewriteBase?
RewriteEngine on
RewriteBase /app1/
RewriteCond $1 !^(index.php|gfx|css|js|robots.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
0 para resposta № 3
Tudo bem, então está funcionando agora. Depois de algumas horas de depuração. Eu não sei exatamente o que aconteceu, mas acho que estava faltando um AllowOverride All
no meu vhost padrão. Após o reinício do apache e este htaccess em cada pasta / app / app1 /, ele começou a funcionar:
RewriteEngine on
RewriteCond $1 !^(index.php|gfx|css|app|js|robots.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Obrigado a todos que contribuíram para minha pergunta.