Lachezar Raychev Lachezar Raychev - 3 years ago 152
PHP Question

CodeIgniter URL not found

enter code here
I got this code in my .htaccess file:

RewriteEngine On
RewriteBase /projFolder

### Canonicalize codeigniter URLs

# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(mycontrol(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]

# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]

# Enforce www
# If you have subdomains, you can add them to
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301]

# Enforce NO www
#RewriteCond %{HTTP_HOST} ^www [NC]
#RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]


# 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]

# 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 index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

My project is in /var/www/projFolder -> the structure in that folder is


i changed $route['default_controller'] = "mycontrol"; in the config routes.php file.
if i type the url localhost/projFolder/ it load the default mycontrol.php controller and the index function from that controller. If i go localhost/projFolder/myFunction -> meaning that i want to load myFunction from the default controller it gives me "The requested URL was not found on this server." Can anybody help? Thanks.

Answer Source

open your config/routes.php file

add this line:

$route['mycontrol/(:any)'] = "mycontrol/index";

then i never used a so huge .htaccess with codeigniter, i always use this and it works great:

RewriteEngine On
RewriteBase /projFolder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /projFolder/index.php/$1 [L]

to remove index.php you have to use htaccess and change in config/config.php:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download