Lachezar Raychev
Lachezar Raychev

Reputation: 2113

CodeIgniter URL not found

enter code hereI 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

/application
/system
/user_guide
.htaccess
index.php

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.

Upvotes: 3

Views: 18225

Answers (3)

Welcome Always
Welcome Always

Reputation: 367

edit you .htaccess fiel to:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
</IfModule>

Upvotes: 1

Filippo oretti
Filippo oretti

Reputation: 49817

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:

$config['index_page']='';

Upvotes: 5

Boris
Boris

Reputation: 802

Although mycontrol is the default controller, it's not going to work, because it expects to find a controller called myFunction when you type localhost/projFolder/myFunction. If you want to access myfunction try to type localhost/projFolder/mycontrol/myFunction. Using this approach you will call the controller and ask for a specific function.

Upvotes: 0

Related Questions