这是我想要做的:我使用的是CodeIgniter,所以所有的URL都是http://example.com/index.php/controller/function 。 不过,我写的脚本本质上是一个带有一些内置统计函数的优化链接缩写,所以我希望所有的URL都是http://example.com/link的forms。 不过,我还希望在http://example.com/admin/上提供脚本的pipe理面板。 我调整了CodeIgniter的“remove index.php from URLs”example .htaccess来适应我的情况,它在我的本地主机(EasyPHP 5.3.9)上正常工作,但是当我把它上传到生产服务器(HostGator)时,所有的pipe理面板的请求正在像普通链接一样处理,并传递给链接控制器( index.php/redirection/link )而不是pipe理控制器( index.php/admin )。 这是我的.htaccess:
<IfModule mod_rewrite.c> RewriteEngine On # 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 the administration panel, # and if so sends the request to the admin controller RewriteRule ^admin/?$ index.php/admin/ [L] RewriteRule ^admin/([^.]+)/?$ index.php/admin/$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 the redirect controller RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/redirection/link/$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>
有什么我做错了吗? 任何帮助或build议,将不胜感激!
从.htaccess中删除下面的行
RewriteRule ^admin/?$ index.php/admin/ [L] RewriteRule ^admin/([^.]+)/?$ index.php/admin/$1 [L]
添加这两行routes.php
$route['admin']="<directory_name_in_contollers>/<controller_name>"; $route["admin/(:any)"]="<directory_name_in_contollers>/$1";
例:
$route['admin']="admin/welcome"; $route["admin/(:any)"]="admin/$1";
这里welcome.php是一个控制器放在application\controllers\admin\welcome.php
如果您的应用程序位于子目录“app_name”中,则在“RewriteEngine On”命令下面放置“ RewriteBase / ”或“ RewriteBase / app_name / ”。
希望有所帮助。
Alfradique