Htaccess Problem With HTTP Form Posts

H

I had problems with my HTTP form posts working properly after implementing a htaccess script. The htaccess script basically redirects the non-www version of my website to the www version.

However this caused problems with HTML form postings that posted to the non-www version, as the form postings would just go missing – as if a blank form was posted.

The solution? Exclude form posts from the redirect:

RewriteCond %{REQUEST_METHOD} !^POST$
RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteRule (.*) http://www.example.com/$1 [R=301,L]

This is inefficient though, and if I wasn’t using an off-the-shelf application, I would code my forms and scripts to not POST to the non-www version of my domain. For example, forms should all post to www.example.com instead of example.com. This way, posts will not be redirected by the htaccess code.

Similar Posts:

About the author

Alvin Poh

I've over 17 years of entrepreneurship experience, having built a tech company to be the top in the country, which was subsequently acquired for an 8-figure sum. As CEO, I led the company through robust growth to 150 employees across 4 countries. After the acquisition, I embraced minimalism, sold off my personal possessions, and started living around the world.

Read more about my story here.

Add comment

By Alvin Poh

About Author

I've over 17 years of entrepreneurship experience, having built a tech company to be the top in the country, which was subsequently acquired for an 8-figure sum. As CEO, I led the company through robust growth to 150 employees across 4 countries. After the acquisition, I embraced minimalism, sold off my personal possessions, and started living around the world.

Read more about my story here.