本文介绍了codeIgniter多应用的.htaccess问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有codeIgniter .htaccess文件的问题,并希望有人能帮帮我!我不知道正恩pressions或如何使用htaccess的,我很新的这个东西!

I have a problem with CodeIgniter .htaccess file and hope that somebody can help me!I don't know regular expressions or how to use the .htaccess, I'm very new with this things!

我的问题是:

我有文件,这个结构(多应用程序):

I have this structure of files (multi application):

- application
    - admin
    - site
- system
- index.php
- admin.php

这的.htaccess(即在本地主机上正常工作!)

And this .htaccess (that works fine on localhost!)

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

我想要做的是:

What I want to do is:

访问我的网站(前端)与 http://www.mydomain.com/ 和我的管理(后端)为 http://www.mydomain.com/admin/

Access my web site (frontend) with http://www.mydomain.com/And my admin (backend) as http://www.mydomain.com/admin/

我不知道为什么这工作得很好我的本地服务器上。

I don't know why this works fine on my local server.

我希望有人能帮助我。

I hope someone can help me.

UPDATE

我把它用这个工作:

I got it to work using this:

RewriteEngine on

# If the user types "index.php" or "admin.php".
RewriteCond $1 !^(index\.php|admin\.php|images|robots\.txt)

# If the user types just "admin".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin$ admin\.php [L,QSA]

# If the user enter in any admin section, like "admin/section".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin\/(.*)$ admin\.php/$1 [L,QSA]

# If the user types any site section, like "site/section".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index\.php/$1 [L,QSA]

这样我可以访问 http://www.mydomain.com/admin 或的(即指向管理。 PHP的根目录下)

This way I can access http://www.mydomain.com/admin or http://www.mydomain.com/admin/any-section (that points to "admin.php" on the root directory)

和我可以访问 http://www.mydomain.com/ 或的(即分的根目录下的index.php)

And I can access http://www.mydomain.com/ or http://www.mydomain.com/any-section (that points to "index.php" on the root directory)

感谢您的帮助!

推荐答案

首先,这是多余的:

RewriteCond $1 !^(index\.php|images|robots\.txt)

因为你的其他条件已经照顾现有的文件和目录,所以我建议将其删除。

because your other conditions already take care of existing files and directories so I'd suggest to remove it.

如果你想/管理员改写为admin.php的你重写规则是错误的,与当前的规则,这将导致/index.php/admin。你没有提到如果是这样的问题,如果是这样做:

Your rewrite rule is wrong if you want /admin to rewrite to admin.php, with your current rule it will result in /index.php/admin. You didn't mention if that's the problem, if it is do this:

RewriteRule ^/admin$ admin.php [L,QSA]
RewriteRule ^(.*) index.php/$1 [L,QSA]

您也可以调试使用RewriteLog改写:的http://的httpd .apache.org /文档/ 2.0 / MOD / mod_rewrite.html#rewritelog

如果不解决这个问题,请描述当前的行为和你所期望的,否则就很难帮助。

If that doesn't fix it please describe the current behaviour and what you expect, otherwise it's difficult to help.

这篇关于codeIgniter多应用的.htaccess问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 15:20