首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么代码点火器路由不工作,找不到404页?

为什么代码点火器路由不工作,找不到404页?
EN

Stack Overflow用户
提问于 2019-06-09 22:57:43
回答 1查看 40关注 0票数 0

我有一张表格来提交财产详细信息。我在CodeIgniter中构建,我在我的表单中有一个jquery脚本来检查表单是否有效,还可以使用dropzone提交图像。但是当我添加路由时,它不起作用。

代码语言:javascript
复制
$route['image-upload']['post'] = 'property/uploadImages';

这里控制器: Property.php方法。:uploadImages()

uploadImages():我在这里上传图片,这些图片来自于dropzone拖放文件上传。

我的.htaccess文件

代码语言:javascript
复制
<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():

代码语言:javascript
复制
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;


}

当我调用url http://www.cerdvillas.dev.cc/admin/image-upload/post时,它显示"404页未找到“

EN

回答 1

Stack Overflow用户

发布于 2019-06-10 00:55:11

您需要在.htaccess文件中指定基本重写。此外,这个文件中的大部分代码都被注释掉了。在您的.htaccess代码中使用它

代码语言:javascript
复制
<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>

考虑阅读mod_rewrite documentation以了解有关Apache mod_rewrite规则的更多信息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56515643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档