user2670787
user2670787

Reputation: 23

htaccess rewriterule preserve post data

The address of the contact form of my website is

www.mysite.com/contact

and the actual contact form address is www.mysite.com/contact.php

When the user fills the contact form, i want contact.php to receive the post data coming from "/contact". I created a folder named contact and put a .htaccess file with the content below

RewriteRule (.*) /contact.php 

But the post data is lost after the form is submitted and /contact is redirected to contact.php. Any ideas to solve it?

Upvotes: 2

Views: 1730

Answers (1)

Jon Lin
Jon Lin

Reputation: 143966

  1. Remove the contact directory.
  2. Put this rule in the htaccess file in your document root

    RewriteRule ^contact/?$ /contact.php [L]
    

The reason why you are losing your POST data and getting redirected is because if there is a contact directory, and you request /contact, the mod_dir module will redirect you to /contact/ to enforce trailing slashes for requests to directories. The redirect and the rewrite both get applied and thus you see /contact.php.

Upvotes: 1

Related Questions