【问题标题】:CodeIgniter .htaccess Affecting FormsCodeIgniter .htaccess 影响表单
【发布时间】:2015-04-03 23:15:12
【问题描述】:

从 URL 中删除 index.php 导致我的表单页面无法接收 POST 数据。

此表单位于 URL http://localhost/guestbook/

以下表单标签有效:

<form method="post" action="http://localhost/index.php/guestbook/">

这(并将其留空)不起作用:

<form method="post" action="http://localhost/guestbook/">

第一个确实可以正常工作,但是它将用户看到的 URL 更改为操作 url - 我希望将 index.php 保留在 URL 之外。

这是我的 htaccess。

RewriteEngine On
RewriteBase /

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

如何让表单提交到重写后的 URL?

【问题讨论】:

  • 使用相对路径
  • @Tpojka 那也没用。
  • 其他控制器是否在没有index.php 的情况下工作,无论 POST 操作吗?

标签: php forms .htaccess codeigniter post


【解决方案1】:

在配置文件中更改它

$config['index_page'] = 'index.php';

到这里

$config['index_page'] = '';

可能工作正常

【讨论】:

    【解决方案2】:

    试试这个可能会有所帮助 Htaccess 文件将是:

    <ifmodule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{REQUEST_URI} ^system.*
        RewriteRule ^(.*)$ /index.php/$1 [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php/$1 [L]
    </ifmodule>
    

    并修改配置文件application/config.php$config设为空白

    $config['index_page'] = '';
    

    【讨论】:

      【解决方案3】:

      打开 config.php 并进行以下替换

      $config['index_page'] = "index.php"
      

      $config['index_page'] = ""
      

      只需替换

      $config['uri_protocol'] ="AUTO"
      

      $config['uri_protocol'] = "REQUEST_URI"
      

      并在 HTACCESS 文件中放入以下代码

      RewriteEngine on
      RewriteCond $1 !^(index\.php|resources|robots\.txt)
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php/$1 [L,QSA]
      

      【讨论】:

        猜你喜欢
        • 2013-05-14
        • 1970-01-01
        • 1970-01-01
        • 2013-12-01
        • 1970-01-01
        • 2016-06-27
        • 2013-09-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多