.htaccess Rewrite Rules Not Working (CodeIgniter)
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
Related videos on Youtube
stevenmirabito
Updated on September 18, 2022Comments
-
stevenmirabito over 1 year
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 ofhttp://example.com/link
. However, I would also like the script's admin panel to be available athttp://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!
-
Richard almost 12 yearsDo 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
-
stevenmirabito almost 12 years@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!
-
HopelessN00b about 9 yearsAdministration panels are off topic. Even the presence of an administration panel on a system, because they take over the systems in strange and non-standard ways, making it difficult or even impossible for actual system administrators to manage the servers normally, and tend to indicate low-quality questions from users with insufficient knowledge for this site.
-