skip to Main Content

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>

3

Answers


  1. Chosen as BEST ANSWER

    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.:)


  2. 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

    Login or Signup to reply.
  3. 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>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search