Web Development and stuff…

Archive for the ‘mod_rewrite’ tag

301 Redirect losing POST data

with 4 comments

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?

del.icio.us Digg DZone reddit SlashDot StumbleUpon Technorati

Written by Thijs Lensselink

February 20th, 2009 at 9:47 am

Posted in Code, Tech

Tagged with , , ,

Forcing a trailing slash with mod_rewrite

without comments

I’m doing some SEO optimization for a couple of websites. And one of the small steps is to force a trailing slash on all URL’s that do not point to a file on the server. The reason I’m doing this is to go around the duplicate content problem.

/trip/80
/trip/80/

Both point to the same content. But a crawler would see this as two different URL’s. Which off course is correct. But this can lead to duplicate content being indexed in search engines. Which could result in penalties for the site in question. So to fix this problem we add three simple lines to the main .htaccess file

# If a requested file does not exists
RewriteCond %{REQUEST_FILENAME} !-f

# If a requested directory does not exist
RewriteCond %{REQUEST_FILENAME} !-d

# Force a trailing slash to the request
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

del.icio.us Digg DZone reddit SlashDot StumbleUpon Technorati

Written by Thijs Lensselink

February 17th, 2009 at 7:29 am

Posted in Code, Tech

Tagged with , , , ,