【问题标题】:Keep POST with rewrite module in htaccess在 htaccess 中使用重写模块保留 POST
【发布时间】:2015-10-08 10:36:27
【问题描述】:

我创建了一个 PHP 函数,它可以从插入的 uri 中获取控制器、模型和视图。

用户指定一个网址,例如:www.my-site.com/news/creation 我的 .htaccess 在我的 index.php 上发送请求。

在我的 index.php 中,我的函数调用模型、控制器和视图。

效果很好。

但是当我提交带有“post”字典的表单时。

字典已清空。

我怎样才能保留它?

RewriteEngine On 
RewriteRule !\.(js|ico|gif|jpg|png|css|html|swf|flv|xml)$ index.php [QSA,L]

编辑:

我的错误来自我的 html,我的表单中的输入没有 'name' 属性。

这是我的工作重写代码:

.htaccess

RewriteEngine On 
RewriteRule !\.(js|ico|gif|jpg|png|css|html|swf|flv|xml)$ index.php [QSA,L]

index.php

    $full_url = 'http://'.$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI];
    $real_uri = str_replace(APPLICATION_PATH, '',$full_url );
    $array_uri = explode('/', trim($real_uri, '/'));

【问题讨论】:

  • “保留我的帖子”是什么意思?

标签: php .htaccess post url-rewriting


【解决方案1】:

根据重定向的定义,重定向 post 请求不会将数据重新发送到新的 url。如果您想将数据获取到服务器上的其他文件,请改用内部重写。如果您想将数据获取到不在您服务器上的 url,您的服务器将需要代理它。 我建议只修复您的数据发布到的网址,并在您的规则中排除该网址

但是,您在问题中发布的规则不会执行重定向。如果发生重定向,则重定向源自 index.php 中的代码。

【讨论】:

    猜你喜欢
    • 2014-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-22
    • 2014-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多