Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Here's what I want to do: I'm using CodeIgniter, so all URLs are in the form of http://example.com/index.php/controller/function. However, the script I've written is a essentially a glorified link shortener with some built-in statistics functions, so I want all of the URLs to be in the form of http://example.com/link. However, I would also like the script's admin panel to be available at http://example.com/admin/. I adapted the CodeIgniter "remove index.php from URLs" example .htaccess to fit my situation, and it works correctly on my localhost (EasyPHP 5.3.9), but when I upload it to the production server (HostGator), all of the requests for the administration panel are being handled like a regular link and passed to the link controller (index.php/redirection/link) instead of the admin controller (index.php/admin). Here's my .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>

Is there something I'm doing wrong? Any help or suggestions would be appreciated!

share|improve this question
1  
Do you know if the "AllowOverride" option is set correctly that you are actually allowed to use htaccess files to the full potential ? httpd.apache.org/docs/2.0/mod/core.html –  Richard Jun 7 '12 at 2:25
    
@Richard No, I don't know, and it doesn't seem to be listed in phpInfo. I will contact HostGator about this tomorrow to see if it's something on their end (I actually didn't think about that!). Still, if anyone sees any other issues, please let me know! –  stevenmirabito Jun 7 '12 at 2:51
add comment

2 Answers

Remove the below lines from .htaccess

RewriteRule ^admin/?$ index.php/admin/ [L]
RewriteRule ^admin/([^.]+)/?$ index.php/admin/$1 [L]

Add this two line routes.php

$route['admin']="<directory_name_in_contollers>/<controller_name>";
$route["admin/(:any)"]="<directory_name_in_contollers>/$1";

Example:

$route['admin']="admin/welcome";
$route["admin/(:any)"]="admin/$1";

Here welcome.php is a controller places at application\controllers\admin\welcome.php

share|improve this answer
add comment

Below the command "RewriteEngine On"put "RewriteBase /" or "RewriteBase /app_name/" if your application is in a subdirectory "app_name".

Hope that helps.

Alfradique

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.