redirect to URL via PHP
<p>I have a form at index.php that takes in user input, it the includes and sends the user input to another php file for processing.</p>

<p>Here is the code of index.php:</p>

<pre><code>&lt;?php
if(isset($_GET['q'])){
    include_once "form.php";
    exit(0);
}
?&gt;
&lt;!Doctype HTML&gt;
&lt;html lang="en"&gt;
    &lt;head&gt;
        &lt;meta charset="utf-8" /&gt;
        &lt;title&gt;Search&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;form method="get"&gt;
         &lt;input type="text" name="q" /&gt;
    &lt;/form&gt;
    &lt;/body&gt;
 &lt;/html&gt;
</code></pre>

<p>When one submits the form it goes to <code>http://mysite.com/?q=textUserEntered</code> (if just the domain was visited before) or <code>http://mysite.com/index.php?q=textUserEntered</code> (if index.php is visited before)</p>

<p>How can I get it to go to <code>http://mysite.com/form?q=textUserEntered</code> or <code>http://mysite.com/index.php/form?q=textUserEntered</code> while still passing the form data to form.php</p>

<p>I tried this in the beginning index.php and form.php, it navigates to the URL but doesn't pass the data to form.php and instead goes to a 404 error page.</p>

<pre><code>if(!empty($_GET['q']))
{
    header("Location: form?q=".rawurlencode($_GET['q']));
    exit;
}
</code></pre>

<p><strong>Update:</strong></p>

<p>I can't use the action attribute because adding form.php to the value of the action attribute would make the URL <code>http://mysite.com/form.php?q=userEnteredText</code> not <code>http://mysite.com/form?q=userEnteredText</code></p>
