0

I have a rewrite rule to rewrite www.mysite.com/default.aspx to www.mysite.com.

RewriteRule ^default.aspx$ / [NC,R=301,L]

On that site i have an asp.net server Button. When i click the button it tries to go to postback to default.aspx, but gets 301'd to the root. This prevents the button's click event from triggering.

How can i redirect default.aspx, without breaking my button's event?

3

You can add this condition RewriteCond %{REQUEST_METHOD} ^GET$ just before rewrite rule to redirect only on GET requests:

RewriteCond %{REQUEST_METHOD} ^GET$
RewriteRule ^default.aspx$ / [NC,R=301,L]

This will allow to POST to default.aspx .. but then it will not be redirected at all.

Ideally you would need to fix your server side / HTML: look at your <form action"XXX"> -- change action to / instead of default.aspx (P.S. I'm not familiar with ASP.NET much and cannot 100% that this is how .NET really works, but this is the way how you can fix it if it would be PHP, for example). The idea is -- fix the source of the problem -- so the form gets submitted to / in first place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.