CodeIgniter多应用程序.htaccess问题 [英] CodeIgniter multi-application .htaccess problem
问题描述
我有一个问题CodeIgniter .htaccess文件,希望有人可以帮助我!
我不知道正则表达式或如何使用.htaccess,我对这个东西很新!
我的问题是:
我有这种文件结构(多应用程序):
- application
- admin
- site
- system
- index.php
- admin.php
这个.htaccess(在localhost上可以正常工作。)
FollowSymLinks
选项-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]
我想要做的是:
访问我的网站前端)与 http://www.mydomain.com/
我的管理员(后端)作为 http://www.mydomain.com/admin/
我不知道为什么这在我的本地服务器上正常工作。
我希望有人可以帮助我。
UPDATE
我使用这个工具:
RewriteEngine on
#如果用户键入index.php或admin.php。
RewriteCond $ 1!^(index\.php | admin\.php | images | robots\.txt)
#如果用户只输入admin。
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule ^ admin $ admin\.php [L,QSA]
#如果用户输入任何管理部分,如admin / section。
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule ^ admin\ /(.*)$ admin\.php / $ 1 [L,QSA ]
#如果用户键入任何网站部分,如site / section。
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule ^(。*)$ index\.php / $ 1 [L,QSA] $ b $这样我可以访问 http://www.mydomain.com/admin 或 http ://www.mydomain.com/admin/any-section (指向根目录上的admin.php)
我可以访问 http://www.mydomain.com/ 或 http://www.mydomain.com/any-section (指向根目录上的index.php)
感谢您的帮助!
解决方案首先这是多余的: p>
RewriteCond $ 1!^(index\.php | images | robots\.txt)
因为您的其他条件已经处理现有的文件和目录,所以我建议删除它。
您的重写规则是错误的,如果你想/ admin重写到admin.php,与您当前的规则,将导致/index.php/admin。你没有提到是否是问题,如果是这样做:
RewriteRule ^ / admin $ admin.php [L ,QSA]
RewriteRule ^(。*)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屋!