rybo111 rybo111 - 3 months ago 10
PHP Question

mod_rewrite won't retain $_POST vars on Apache 2.4

mod_rewrite
is not passing my $_POST variables and GoDaddy have assured me it is because I need to alter my setup for Apache 2.4.

Here is my code:

.htaccess

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


index.php

<?php
$q = explode("/", $_SERVER['REQUEST_URI']);
if ($q[1] != "") {
switch($q[1]) {
case "test":
include("test.php");
break;
}
}
?>


test.php

<?php
if (isset($_POST["submitButton"])) {
echo "Submitted";
} else {
echo "Not submitted";
}
?>
<form method="post">
<input type="submit" name="submitButton">
</form>


When submitting via /test, it shows "Not submitted".

When submitting via /test.php, it shows "Submitted".

I have tried this exact setup on another host and it works fine.

What needs changing in order for it to work?

Answer

The reason this happens is because GoDaddy's settings point the user to missing.html when the URL isn't a recognised file.

The fix is to ignore GoDaddy's .htaccess file by adding Options -Multiviews to your own .htaccess file.