2

I am facing a different problem in codeigniter.

When I try to access the videos page in my site, it will redirect to 404.shtml page. But cvideos.php file exists in my controllers folder.

If I access like this http://domain-name/videos , then it will be redirected like this //domain-name/500.shtml

And If I access the same page like this //domain-name/videos/myvideos, then then it will be redirected like this //domain-name/404.shtml

Also, If I change the controller name from videos to some other name like videoss it works fine. Can anyone tell wats the issue.

I used this line in my .htaccess also just for testing. But no use.

RewriteRule ^videos/$ index.php/videoss/ [L]

Sindhuja
  • 21
  • 1
  • 1
  • 3

4 Answers4

5

Your controller needs to be the same name as the class it contains.

hence -

<?php

controller Videos extends Controller {

 /* bla */
}

?>

should be saved as:

videos.php in the "controllers" directory.

Nothing else will work.

also your rewrite rule has two "s"'s, but that might be intentional.

and it looks like what you are trying to do with .htaccess can be achieved with CI's routing


Edit: .htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

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

please note I did not create this - it was found by scouring the CI forums. It's a rather thorough htaccess however.

Don't forget to set the value of "index.php" to "" in your config.

Community
  • 1
  • 1
Ross
  • 18,117
  • 7
  • 44
  • 64
  • Thanks for ur quick response. Yes.. exactly.. Here by mistake I have typed the filename as cvideos.php. But the original name is videos.php. Regarding rewrite rule just I redirected to some other page If I typed videos in URL. I also have the videoss.php file in my controller directory. My Problem is, the same videos.php file works If I access like videoss.php. http://domain-name/videoss If I access this url it works fine, But the http://domain-name/videos wont work and redirection issue occurs for me. – Sindhuja Nov 08 '10 at 12:37
  • struggling to understand exactly what you want to do. remove the rewrite rule for the time being, create a controller called "videos.php", class name "Videos" and access it from domain-name.com/index.php/videos - does this do what you want? if not you will need to clarify further. – Ross Nov 08 '10 at 12:52
  • Sorry. I will try to explain you clearly. If I disable .htaccess and access the page like this http://domain-name/index.php/videos it works fine. But after enabled .htaccess, If I access the same page like this http://domain-name/videos then redirect issue occurs . Controller name is videos.php and class name is Videos. – Sindhuja Nov 08 '10 at 13:01
  • so you're trying to remove index.php from URLs? - see my edited response for a working htaccess. – Ross Nov 08 '10 at 13:07
  • That's not my problem.. I already removed index.php and it works fine for every other files. For Ex, I have photos.php file. http://domain-name/photos works fine. Specially It wont work only for videos file. Everything is perfect in videos.php file. Suppose If I change the videos.php file name as some other name it works fine. So my issue is particularly only for videos file – Sindhuja Nov 09 '10 at 09:59
3

base_url is case sensitive

localhost/site/controller = c:...\site

localhost/SITE/controller = c:...\SITE

Jessé Catrinck
  • 2,227
  • 19
  • 20
1

make sure you are not missing .htaccess file in your root directory. Or check for its accuracy. Make sure uri_protocol and base_url are set correctly in config.php.

for sample, i am copying my .htaccess file here

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /your_dir

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

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

</IfModule>

I used this to get rid of index.php in url.

Max
  • 1,528
  • 21
  • 33
0

I had a similar problem when transferring a CI site from WAMPP to a LAMPP that someone else had made. It would seem that WAMPP was configured to be case-insensitive, as when I converted all my controller/model/view file names and all php strings containing controller/model/view names to lowercase it worked perfectly.

Dave
  • 1