1

I tested my site many times but I am not able to resolve Page not found error. well,

1 step: I create one controller and called welcomelogin.php - where I store two functions

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class WelcomeLogin extends CI_Controller {
public function index()
{
    $this->home();
}
public function home(){

    $this->load->helper('url');
    $this->load->view('login');
}

public function inside(){
    $this->load->helper('url');
    $this->load->view('inside');    
}

2- step: In my rote.php file I simple perform follwing:

$route['default_controller'] = "welcomeLogin";
$route['404_override'] = '';

3- step: Inside view folder I create two files one is login.php & second is inside.php with login.php contains login form and inside.php contain simple html.

Now I got login page as home page of my website which is working fine: http://localhost/website/Codeigniter_Project/MyProject/

When I do following I get page not found error: I tried with two ways and both gives me same error:

1-st way: by direct giving view name and result page not found localhost/website/Codeigniter_Project/MyProject/inside

2-nd way: by giving controller name and then view but result page not found localhost/website/Codeigniter_Project/MyProject/welcomelogin(controllername)/inside

Please help me as I spend almost 2 hours by searching and applying different answers and yes there are similar questions on stack and some have answer which I already tried but didn't work & those question is bit different then mine. Thanks for your time guys.:) I am running on localhost server and my apache mod_rewrite is on. thanks. & I am new to codeigniter thanks

My .htaccess file:

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /website/Codeigniter_Project/MyProject/


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

</IfModule>

<IfModule !mod_rewrite.c>

    # Without mod_rewrite, route 404's to the front controller
    ErrorDocument 404 /index.php

</IfModule>
Jimil
  • 546
  • 1
  • 12
  • 30

3 Answers3

0

Please try with this url

http://localhost/website/Codeigniter_Project/MyProject/index.php/inside

hope this will work if you did not restrict the flow of url with .htaccess

Arun
  • 3,316
  • 6
  • 33
  • 71
  • Hi not working and my .htaccess file contains: Deny from all so do you think I should change anything there if yes then can you provide me the code as not so sure what could be there. thanks – Jimil Mar 19 '15 at 05:11
  • @user2268488, i'm using the `htaccess` from http://www.farinspace.com/codeigniter-htaccess-file/. It contains all the necessory information you need :) – Arun Mar 19 '15 at 05:13
  • Hi bro, I implement my .htaccess file with above and it seems not working as I tried by giving controller name/method name in which method name contains $this->load->view() but still not working:( – Jimil Mar 19 '15 at 05:26
  • you missed the `Rewritebase` value. As per your code it will be `/website/Codeigniter_Project/MyProject/`. – Arun Mar 19 '15 at 05:29
0

PHP CI code seems fine, you should check .htaccess file,

As you added .htaccess file in question, you should add RewriteBase from your web directory to project home, see below sample code

RewriteBase /website/Codeigniter_Project/MyProject/

Updated htaccess file

<IfModule mod_rewrite.c>
    RewriteEngine On
    ########### TODO: deploying on subdir must rewrite this
    RewriteBase  /website/Codeigniter_Project/MyProject/

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

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

    # you could simply throw this into an htaccess file the directory you want displayed
    Options -Indexes

</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>
Girish
  • 11,254
  • 3
  • 32
  • 48
  • Hi bro can you tell me do I have to put my controller name here in .htaccess file: # If your default controller is something other than # "welcome" you should probably change this RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301] – Jimil Mar 19 '15 at 05:34
  • So rather than welcome(/index) do I have to replace to my controller name welcomelogin in small or caps as I have class WelcomeLogin – Jimil Mar 19 '15 at 05:36
  • ok, remove `### Canonicalize codeigniter URLs` section in .htaccess, ci route automatic detect it... and naming conventions could be impact on os version, you can read more here https://ellislab.com/codeigniter/user-guide/general/styleguide.html – Girish Mar 19 '15 at 05:40
  • Hi I update my .htaccess file can you please have a look – Jimil Mar 19 '15 at 05:46
  • you should use initial htaccess file see in answer updated section – Girish Mar 19 '15 at 09:07
  • Hi bro, really thanks for your reply really appreciate but it's still not work what bad luck of mine. Now I found one solution is if you can send me whole codeigniter project where some view with links connecting them then I'll download it from github. then I do tick as your answer please if can do it for me it will be big favor thanks – Jimil Mar 19 '15 at 10:40
  • ok, I'll do later if not solve, probably you are using wrong url `http://localhost/website/Codeigniter_Project/MyProject/` double check `website/Codeigniter_Project/MyProject` folder name and location – Girish Mar 19 '15 at 10:52
  • Hi bro, thanks for your help however many people stuck with this sorts of issue so I just put correct answer through as answer. – Jimil Mar 19 '15 at 22:46
0

There is no any modification required in my case it's just required to use index.php file in the path so path should be like this http://localhost/website/Codeigniter_Project/MyProject/index.php/welcomelogin/inside

I found this answer through a tutorial which I found while research my answer online link is http://tutorialcodeigniter.com/beginners/creating-controller.html - For how to remove index.php from the url. Best explain and work for me - Cannot remove index.php from CodeIgniter URL

But thanks anyways who try to help me for my query.:)

Community
  • 1
  • 1
Jimil
  • 546
  • 1
  • 12
  • 30