Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>action</code> is the target of the form. <code>method</code> is the submit type. <code>method</code> would be what determines if <code>$_POST</code> is populated or <code>$_GET</code>.</p> <p><strong>EDIT</strong></p> <p>after a down vote, and some changes to the question, it seems that this response is not what the questioner is looking for.</p> <p><code>/questions/ask/submit</code> is probably controlled by a CMS. meaning most requests are redirected to a single file, which then interprets them. This redirect is done with mod_rewrite usually, as your question indicates. mod_rewrite accepts a number of 'switches' to tell it what to do. That being said, there is no known bug with mod_rewrite 'messing up' <code>$_POST</code> data. Apache is what passes this data to PHP. mod_rewrite passes that to Apache. If your <code>$_POST</code> data gets messed up, you have a bad rule some where.</p> <p>Here is an example of how a common CMS, WordPress, directs all traffic, regardless of method, to a central controller, which then interprets the untarnished <code>$_POST</code> data:</p> <pre><code># BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &lt;/IfModule&gt; # END WordPress </code></pre> <p>TOP DOWN EXPLANATION:</p> <ul> <li>only execute this if the mod_rewrite module is active</li> <li>turn on the rewrite engine, so that it accepts your new rules</li> <li>make all your rewrites, rewrite to the document root <code>/</code></li> <li>if the request was directly to <code>index.php</code> then force mod_rewrite to not process more rules and load index.php</li> <li>if the requested url does not directly map to a file</li> <li>AND if the requested url does not direclty map to a directory</li> <li>send all data, including requested url, _GET, _POST, etc, to index.php, and dont process any other rules</li> </ul> <p><strong>EDIT (after sample files were submitted in question)</strong></p> <p>Here are my complete files. With these exact files, on a Apache 2.2 and PHP 5.4 install, this works perfectly.</p> <p><strong>.htaccess</strong></p> <pre><code># BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &lt;/IfModule&gt; # END WordPress </code></pre> <p><strong>index.php</strong></p> <pre><code>&lt;?php $q = explode("/", $_SERVER['REQUEST_URI']); if($q[1]!=""){ switch($q[1]){ case "test": include("test.php"); break; } } </code></pre> <p><strong>test.php</strong></p> <pre><code>&lt;?php if(isset($_POST["submitButton"])){ echo "Submitted"; }else{ echo "Not submitted"; } ?&gt; &lt;form method="post" action="/test/submit"&gt; &lt;input type="submit" name="submitButton"&gt; &lt;/form&gt; </code></pre> <p><strong>directory list, so you can compare permissions</strong></p> <p>NOTE: <em>apache runs as nobody.nobody on my test machine</em></p> <pre><code>drwxrwxr-x 2 nobody git 4096 Dec 22 03:34 ./ drwxrwxr-x 3 nobody git 4096 Dec 22 03:26 ../ -rw-rw-r-- 1 nobody git 244 Dec 22 03:29 .htaccess -rw-rw-r-- 1 nobody git 134 Dec 22 03:27 index.php -rw-rw-r-- 1 nobody git 194 Dec 22 03:28 test.php </code></pre> <p>If this does not work for you, you probably have a permission problem. This exact code works.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload