Codeigniter ajax 在托管时调用 404 错误

Codeigniter ajax call 404 error on hosting

我正在尝试在托管上测试 codeigniter 项目;它呈现的索引页面没有问题,但我有一个通过 ajax 请求发送数据的联系表格,此处:

$('#send_mail').submit(function(e) {
e.preventDefault();

$.ajax({
  url: baseurl+'email/send',
  type: 'POST',
  dataType: 'json',
  data: $(this).serialize()
})
.done(function() {
  console.log("success");
})
.fail(function() {
  console.log("error");
})
.always(function() {
  console.log("complete");
});

});

当我提交联系表格时,我收到了这个错误:

 POST http://novaderma.cl/site/email/send 404 (Not Found) jquery.min.js:4

我一直在网上搜索,其他人对 .htacces 文件和 base_url 参数也有类似的问题,所以我也要 post 他们,在这里:

配置文件

$config['base_url'] = 'http://novaderma.cl/site/';
$config['index_page'] = 'index.php';

.htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /site/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/ [L]
  </IfModule>

我不知道如何解决这个问题,所以请帮助我!!

`

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

`

检查此代码

您的站点服务器在 Windows 上的 IIS 上运行,因此 .htaccess 无济于事,因为它适用于 Apache 服务器。

您需要在 site 文件夹中创建 web.config 文件,然后用以下规则填充它:

<rewrite>
        <rules>
             <rule name="Clean URL" stopProcessing="true">
                <match url="^(.*)$" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="/site/index.php/{R:1}" appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>