简体   繁体   中英

Why did Code igniter routes not working, Getting 404 Page Not Found?

I have a form to submit property details. I build in CodeIgniter, I have a jquery script in my form to check the form is valid and also submit images using dropzone. But when I add routes it's not working.

$route['image-upload']['post'] = 'property/uploadImages';

Here Controller : Property.php Method . : uploadImages()

uploadImages() : Here I do uploading of images which comes from dropzone drag and drop file uploading.

My .htaccess file

<IfModule mod_rewrite.c>



    # Make sure directory listing is disabled
    Options +FollowSymLinks -Indexes
    RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$0 [L]

    # NOTICE: If you get a 404 play with combinations of the following commented out lines
    #AllowOverride All
    #RewriteBase /wherever/codeginiter/is

    # Restrict your site to only one domain
    # !important USE ONLY ONE OPTION

    # Option 1: To rewrite "www.domain.com -> domain.com" uncomment the following lines.
    #RewriteCond %{HTTPS} !=on
    #RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    #RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    # Option 2: To rewrite "domain.com -> www.domain.com" uncomment the following lines.
    #RewriteCond %{HTTPS} !=on
    #RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
    #RewriteCond %{HTTP_HOST} (.+)$ [NC]
    #RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

    # Remove index.php from URL
    #RewriteCond %{HTTP:X-Requested-With}   !^XMLHttpRequest$
    #RewriteCond %{THE_REQUEST}             ^[^/]*/index\.php [NC]
    #RewriteRule ^index\.php(.*)$           $1 [R=301,NS,L]

    # Keep people out of codeigniter directory and Git/Mercurial data
    # RedirectMatch 403 ^/(system|\.git|\.hg).*$

    # Send request via index.php (again, not if its a real file or folder)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    <IfModule mod_php5.c>
        RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>

    <IfModule !mod_php5.c>
        RewriteRule ^(.*)$ index.php?/$1 [L]

    </IfModule>

</IfModule>



uploadImages() :

function uploadImages()
{
     $this->load->helper('url');
     if($this->input->post() != NULL ){


    $data = array();

    $config['upload_path'] = 'property-images/';
    $config['allowed_types'] = 'jpg|jpeg|png|gif';
    $config['max_size'] = '2048'; // max_size in kb

    foreach($_FILES['file']['name'] as $key => $value) {

        $config['file_name'] = $_FILES['file']['name'][$key];

        // Load upload library
        $this->load->library('upload',$config);
        // File upload
        if($this->upload->do_upload('file')) {

          // Get data about the file
           $uploadData = $this->upload->data();
           $filename = $uploadData['file_name'];
           $propertyId = 1;
           $imageData = array('path'=>$imgPath, 'propertyid'=>$propertyId);
           $result = $this->property_model->uploadImages($imageData);



         }

       }

       return $result;


}


When I call the url http://www.cerdvillas.dev.cc/admin/image-upload/post its shows "404 Page Not Found"

You need to specify the Base Rewrite in your .htaccess file. Also most of the code in this file is commented out. Use this in your .htaccess code

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder.
    #Additionally this will allow you to create a System.php controller,
    #‘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
    #This last condition enables access to the images and css folders, and the 
    robots.txt file
    RewriteCond $1 !^(index\.php|images|robots\.txt|css)
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

Consider reading up on mod_rewrite documentation to learn more about Apache mod_rewrite rules

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM