【问题标题】:Reroute POST-request to remove /index.php/ [Codeigniter]重新路由 POST 请求以删除 /index.php/ [Codeigniter]
【发布时间】:2016-12-22 23:08:42
【问题描述】:

是否可以更改 POST 请求的路由?

我刚刚发现我必须在我的表单操作属性中包含/index.php/。困扰我一阵子 $_POST 数组是空的,并认为这是 CI 的错误。

我的 .htaccess 目前看起来像这样:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
    RewriteCond $1 !^(phpmyadmin|index\.php|images|robots\.txt)
</IfModule>

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

<Limit GET POST>
order deny,allow
allow from all
</Limit>

<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>

编辑: 表单重定向到我希望它去的地方,但 POST 数据也没有到达那里。

【问题讨论】:

    标签: php .htaccess codeigniter http-post


    【解决方案1】:

    是的,这是可能的。

    如果您使用的是 Apache,请参阅 here。如果您使用的是 Nginx,请参阅here

    可能您使用的是 Apache,所以您的 .htaccess 应该如下所示:

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

    【讨论】:

    • 我已经查看了 10 次文档,并在互联网上搜索了任何可能的方法,但我找不到重新路由此路径的方法。
    • 我的正常 URL 请求正在工作并被重写,因此该部分工作得非常好,但 POST 需要 /index.php/ 才能正确路由,我不明白为什么。
    猜你喜欢
    • 2013-04-13
    • 1970-01-01
    • 2014-08-26
    • 2012-03-30
    • 1970-01-01
    • 2014-02-24
    • 2011-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多