Earlier this week i implemented the forcing of trailing slashes for some websites. And this worked out great.
But today one of the ladies here at the office noticed the contact form on one site wasn’t functioning properly anymore.
So i did some debugging and quickly came to the conclusion the POST data array was empty after a submit of the form. That’s weird i thought. And didn’t really have a clue where to start looking. The code wasn’t touched for a couple of weeks. Bu then i remembered adding the forcing of the trailing slash.
So i browsed to the contact form and did a view source. And there was the problem. The form submitted to
/contact/verstuurd
A URL without a trailing slash. This causes apache to rewrite the url to
/contact/verstuurd/
And this also seems to turn the POST into a GET request.
So to fix it just changed to URL in the form to reflect the correct end point. But i have to say i didn’t expect this to happen. I understand why it happens. And it’s pretty logical. But i wonder if there’s a way around this behavior?



Twitter
I am Thijs Lensselink a Webdeveloper from the Netherlands.
what does your rewrite configuration look like? The fact that it rewrites using a 301 redirect is as far as I know a configuration issue.
Hey Ivo,
My rewrite lines are posted below. Maybe i need to do this without a 301 response if possible?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
ja, je kunt vermoedelijk een RewriteCond erop zetten voor METHOD GET en dan voor post een andere set doen waarbij je de R=301 uit de regel weglaat (dus alleen [L]).
Perfect. Ik heb die 301 nodig maar dat is inderdaad alleen voor GET. Nu heb ik twee rules en dat werk prima.
ty!
RewriteCond %{REQUEST_METHOD} =GET
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
RewriteCond %{REQUEST_METHOD} =POST
RewriteRule [^/]$ %{REQUEST_URI}/ [NC,L]
Thanks for the helpful information