Reputation: 6209
I am setting up a redirect for my wedding website so that http://www.mydomain.com/rsvp.php/q/something
redirects to http://www.mydomain.com/rsvp.php?q=something
, but only on the server-side (that is, the client still sees rsvp.php/q/something
in their address bar).
Now, I have the following in my apache config for this site:
<VirtualHost *>
ServerAdmin [email protected]
ServerName www.mydomain.com
DocumentRoot /var/www/www.mydomain.com
Options -Indexes +FollowSymLinks
RewriteEngine on
RewriteRule ^/rsvp.php/q/(.*) /rsvp.php?q=$1
</VirtualHost>
Now, I also have a meta-redirect at the top of the PHP file (in the event that the user doesn't have anything in the q query variable) that redirects to index.html:
<?php
$userHash = $_GET['q'];
?>
<!doctype html>
<html>
<head>
<title>Wedding - RSVP Page</title>
<?php
// If we don't have a user hash, then let's redirect to the main
// page.
if (!$userHash) {
echo '<meta http-equiv="refresh" content="0; url=http://www.mydomain.com/">';
}
?>
Again, this seems to work ok, with one exception. I'm using a form for the user to input their RSVP data. On submit, it calls a script, submit-form.php
. When the address http://www.mydomain.com/getID.php is accessed, it redirects to index.html, which is not what I want.
If I remove the RewriteRule
, it works as expected, with the exception that I don't get a nice url (I have to use q=something
instead of q/something
). I'm not very good at mod_rewrite, so I'm wondering if someone could give me some assistance to let me know what I'm doing wrong.
Thanks!
Upvotes: 0
Views: 326
Reputation: 5155
you need to tell apache not to rewrite existing files, using RewriteCond
.
in your .htaccess add the following code:
rewriteengine on
Options +FollowSymLinks
RewriteCond %{SCRIPT_FILENAME} !-d #not a directory
RewriteCond %{SCRIPT_FILENAME} !-f #not a file
RewriteRule ^rvsp/([^/\.]+)?$ rvsp.php?q=$1
than, in your rvsp.php file, add this code:
<?php
$q = $_GET['q'];
?>
the action in the form getID.php
should look like this:
http://www.mydomain.com/rvsp/query
where query
is the user input
Upvotes: 1