设置htaccess重写规则后,不发送表单发布数据

时间:2015-01-02 21:54:24

标签: php .htaccess mod-rewrite

我正在使用PHP-login.net框架进行登录,我将该文件夹托管在另一个网站的子文件夹中,并使用htaccess将其重定向到我为该子文件夹创建的主域。

RewriteCond %{HTTP_HOST} ^(www.)?decathlon.ga$ [NC]
RewriteCond %{REQUEST_URI} !^/decathlon/.*$
RewriteRule ^(.*)$ /decathlon/$1 [L]

当我像saint57records.com/decathlon那样工作时它工作正常但是当我添加重定向时,POST数据不是从这个表单发送的。但是,所有链接都应该重定向。

<form action="http://decathlon.ga/login/login" method="post">
<label>Username (or email)</label>
<input type="text" name="user_name" required />
<label>Password</label>
<input type="password" name="user_password" required />
<input type="checkbox" name="user_rememberme" class="remember-me-checkbox" />
<label class="remember-me-label">Keep me logged in (for 2 weeks)</label>
<input type="submit" class="login-submit-button" />
</form>

在页面上,它会执行此检查并向我提供POST为空的错误。

http://decathlon.ga/login/login部分

if (!isset($_POST['user_name']) OR empty($_POST['user_name'])) {
    $_SESSION["feedback_negative"][] = FEEDBACK_USERNAME_FIELD_EMPTY;
    return false;
}

所以一切都重定向到了正确的位置,但有人知道POST数据可能会发生什么,因为重定向?

2 个答案:

答案 0 :(得分:2)

我并非100%清楚您正在尝试做什么,但是您要将所有不匹配^/decathlon/.*$的内容重定向到/decathlon/$1。这意味着http://decathlon.ga/login/login重定向到http://decathlon.ga/decathlon/login/login,这似乎是错误的。

您需要重写第二个RewriteCondRewriteRule,但如果没有更多信息,就无法猜测它们应该是什么。

答案 1 :(得分:1)

您显示的规则是没有进行任何外部重定向,它只是一个内部重写。因此,在此路由到/decathlon目录期间,POST数据将保留。我建议你检查进行此重定向的其他规则的存在。如果mod_dir是真实目录,则外部重定向也可能由login/login等其他模块引起。

作为替代方案,您甚至可以通过在表单的操作路径中直接使用/decathlon/来避免重写:

<form action="http://decathlon.ga/decathlon/login/login"