views:

347

answers:

2

Hello there,

Because of strange cross domain AJAX problems, causing AJAX requests to fail when not using www.(the PHP handler communicating with the request is given in a relative path, so it can't be an address issue or something - that's what this question is about though), I have forced www. using .htaccess :

#enable rewrite engine and set options
Options +FollowSymLinks
RewriteEngine on

#only www.
RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]

This works great. However, I want to allow other webmasters to post one of my forms on their website, using my form URL in their form's action attribute. This always worked, however after my .htaccess change the forms are only submitted when the webmaster adds www. to the action value. Without www. the form will not get submitted.

How should I change my .htaccess file to make sure that these forms are also submitted without www.?

+2  A: 

Most browsers don't forward POSTed data when 301 Redirected... So you will see those requests as a GET of your action url instead.

This behaviour is technically non-compliant but seems to be the commonly accepted approach.

(c.f. http://www.lassosoft.com/Documentation/TotW/index.lasso?9083, http://www.nkuttler.de/2008/11/09/mailman-and-301-redirects/.)

Maybe try 307 Temporary Redirects for your forms? 307 specifically instructs the browser to re-POST the data. http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection

Stobor
is it even a good idea to tell (search engines) that all non-www links are moved to www links? should I maybe make it a normal redirect rather then a "permantently moved" redirect?
Tom
It's a very good idea to tell search engines about the "canonical url" for your site... Amongst other things, it ensures that the various links to both urls combine to more accurately reflect the ranking of your page. In short, 301==good, but for forms, either use 307, or don't redirect your POSTs.
Stobor
+2  A: 

You could use

RewriteCond %{REQUEST_METHOD} ^GET$

which will rewrite only GET requests, leaving POST requests as they are.

webjunkie