CodeIgniter多应用.htaccess问题 [英] CodeIgniter multi-application .htaccess problem
问题描述
我在使用 CodeIgniter .htaccess 文件时遇到问题,希望有人能帮助我!我不知道正则表达式或如何使用 .htaccess,我对这些东西很陌生!
我的问题是:
我有这样的文件结构(多应用程序):
- 应用程序- 行政- 地点- 系统- 索引.php- admin.php
还有这个 .htaccess(在本地主机上运行良好!)
选项 +FollowSymLinks选项 - 索引目录索引 index.php重写引擎开启RewriteCond $1 !^(index.php|images|robots.txt)RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d重写规则 ^(.*)$ index.php/$1 [L,QSA]
我想做的是:
使用 http://www.mydomain.com/ 访问我的网站(前端)我的管理员(后端)为 http://www.mydomain.com/admin/>
我不知道为什么这在我的本地服务器上运行良好.
我希望有人能帮助我.
更新
我用这个让它工作:
RewriteEngine on# 如果用户输入index.php"或admin.php".RewriteCond $1 !^(index.php|admin.php|images|robots.txt)# 如果用户只输入admin".RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d重写规则 ^admin$ admin.php [L,QSA]# 如果用户进入任何管理部分,如admin/section".RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d重写规则 ^admin/(.*)$ admin.php/$1 [L,QSA]# 如果用户键入任何站点部分,例如站点/部分".RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d重写规则 ^(.*)$ index.php/$1 [L,QSA]
这样我就可以访问 http://www.mydomain.com/admin 或
我可以访问 http://www.mydomain.com/ 或 http://www.mydomain.com/any-section(指向根目录上的index.php"目录)
感谢您的帮助!
首先这是多余的:
RewriteCond $1 !^(index.php|images|robots.txt)
因为您的其他条件已经处理了现有的文件和目录,所以我建议将其删除.
如果你想让/admin 重写为admin.php,你的重写规则是错误的,你当前的规则将导致/index.php/admin.您没有提到这是否是问题所在,如果是,请执行以下操作:
RewriteRule ^/admin$ admin.php [L,QSA]重写规则 ^(.*) index.php/$1 [L,QSA]
您也可以使用 RewriteLog 调试重写:http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog
如果这不能解决问题,请描述当前的行为和您的期望,否则很难提供帮助.
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!
My Problem is:
I have this structure of files (multi application):
- application
- admin
- site
- system
- index.php
- admin.php
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:
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]
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)
And I can access http://www.mydomain.com/ or http://www.mydomain.com/any-section (that points to "index.php" on the root directory)
Thanks for the help!
First of all this is redundant:
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.
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]
Also you can debug the rewriting using RewriteLog: http://httpd.apache.org/docs/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问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!