Redirection issue

Apr 17, 2010 at 3:35 AM

I have the following rules set. It works fine, except for the following.

Any request for /category.asp?category=ct&id=12&papa=miagoogle OR

/category.asp?category=ct&id=12

does not properly redirected with 301. Looking at the following what am i doing wrong?

--------------
(This is for normal requests to thank-you-item.html in which case category1.asp will be executed, normal 200 status)
RewriteCond %{HTTPS} ^off$
RewriteRule ^/thank-you-item.html$ /category1.asp?category=ct [L]

(This is for https going to non-https with 301)
RewriteCond %{HTTPS} ^on$
RedirectRule ^/thank-you-item.html$ http://www.mydomain.com/thank-you-item.html  [R=301]

(This is for requests to non www request going to www with 301)
RewriteCond %{SERVER_NAME} ^mydomain\.com$ [I]
RedirectRule ^/category\.asp\?category=ct$ http://www.mydomain.com/thank-you-item.html [U,I,R=301]

(This is for all requests to category=ct$ - meaning anything afterwards even category query string, goes to .html page with 301)
RewriteCond %{SERVER_NAME} ^www\.mydomain\.com$ [I]
RedirectRule ^/category\.asp\?category=ct$ http://www.mydomain.com/thank-you-item.html [U,I,R=301]
---------------

Thanks,

Coordinator
Apr 17, 2010 at 12:35 PM

Your rules don't handle incoming URLs with anything following category=ct.

In regular expressions, the $ is an end-of-line assertion. Therefore your pattern matches URLs that end with category-ct. URLs with additional data following that, such as the ones you identified that "don't work", won't match those patterns. 

If you want the rules to match any URL that begins with /category.asp?category-ct , then you need to remove the $ from the pattern in the RedirectRule.

Apr 19, 2010 at 2:41 PM

Thank you cheeso, that solved the problem.

If i were to learn more on the regular expressions that are used with IIRF, what is the best resource?

Thanks,

 

Coordinator
Apr 19, 2010 at 3:43 PM

start with  the page from the IIRF documentation.  http://cheeso.members.winisp.net/Iirf20Help/html/e013a406-9f3a-4385-b986-6c4c410dad48.htm 

There are links at the bottom of that, that direct you to more information.

 

Apr 22, 2010 at 2:24 AM

Sorry, one more problem that i came across.

(This is for requests to non www request going to www with 301)
RewriteCond %{SERVER_NAME} ^mydomain\.com$ [I]
RedirectRule ^/category\.asp\?category=ct http://www.mydomain.com/thank-you-item.html [U,I,R=301]

After i removed the $, it works fine in terms of redirection, but it does not pass the querystring values. For example: category.asp?category=ct&id=@AF1 it does not carry to thank-you-item.html page.

What am i doing wrong?

Coordinator
Apr 22, 2010 at 2:55 PM

Append QSA to the options. 

Also, are you sure you need [U]  ?

 

Apr 23, 2010 at 2:50 AM

Don't know i need [U] or not, just copied from the sample ini posting.

When you say QSA to the options, how do i add it? for example to the following.

(This is for requests to non www request going to www with 301)
RewriteCond %{SERVER_NAME} ^mydomain\.com$ [I]
RedirectRule ^/category\.asp\?category=ct http://www.mydomain.com/thank-you-item.html [U,I,R=301]

Thanks,

 

Coordinator
Apr 23, 2010 at 11:30 PM

RedirectRule ^/category\.asp\?category=ct http://www.mydomain.com/thank-you-item.html [QSA,I,R=301]

Apr 24, 2010 at 3:49 AM

Changing this is resulting the request to category.asp?category=ct returned as status 200 instead of 301.

For example: http://www.mydomain.com/category.asp?category=ct&id=@AR1 >>> 200 >>> with no redirection or 301.

Thanks,

Coordinator
Apr 24, 2010 at 4:10 AM

what version of the filter are you using?

There was a problem reported previously, with redirections returning 200.  It's been fixed in the latest v2.1 IIRF.  What evrsion are you using?

Apr 24, 2010 at 4:52 AM

It is the June, 2009 version, so i will upgrade to v2.1 and see if the problem persists. Any special care needs to be taken to upgrade?

Thanks,

Apr 24, 2010 at 4:54 AM

Found this link => http://cheeso.members.winisp.net/Iirf20Help/frames.htm - so in the process of upgrading.

 

Coordinator
Apr 24, 2010 at 10:00 AM

I don't know what version was available in June 2009, but yes, you have to take care when upgrading.

There's a  note on upgrading, in the documentation you referenced.  And there's .chm documentation in the downloads page.

 

 

Apr 24, 2010 at 9:34 PM

Upgraded to the V2.0 stable version. Somehow can't figure out still as to why it's happening like i described below.

This is for normal requests to thank-you-item.html in which case category1.asp will be executed, normal 200 status) - This is working fine.
RewriteCond %{HTTPS} ^off$
RewriteRule ^/thank-you-item.html$ /category1.asp?category=ct [L]

(This is for https going to non-https with 301)
RewriteCond %{HTTPS} ^on$
RedirectRule ^/thank-you-item.html$ http://www.mydomain.com/thank-you-item.html  [R=301] - This is working fine.

Following two rules are supposed to pass the entire URL with querystring to thank-you-item.html, which is going to above rule and ultimately failing. The reason for passing all querystring variables is that there is a logic on category1.asp page to count say an id value (for example: http://www.mydomain.com/category.asp?category=ct&id=@411) of @411 and increment by 1. That logic is not happening because it is not redirecting to category1.asp with the @id=@411.

(This is for requests to non www request going to www with 301)
RewriteCond %{SERVER_NAME} ^mydomain\.com$ [I]
RedirectRule ^/category\.asp\?category=ct http://www.mydomain.com/thank-you-item.html [QSA,I,R=301]

(This is for all requests to category=ct$ - meaning anything afterwards even category query string, goes to .html page with 301)
RewriteCond %{SERVER_NAME} ^www\.mydomain\.com$ [I]
RedirectRule ^/category\.asp\?category=ct http://www.mydomain.com/thank-you-item.html [QSA,I,R=301]

By adding QSA it is passing querystring variables with 301, but since there is a rewrite rule above, it is still not passing to the final page; which is category1.asp. What can i do to pass it?

Thanks,

 

Coordinator
Apr 26, 2010 at 5:06 PM
bhaktavatsal wrote:

By adding QSA it is passing querystring variables with 301, but since there is a rewrite rule above, it is still not passing to the final page; which is category1.asp. What can i do to pass it?

I understand these words, but I don't know exactly what the problem i, so I'm going to guess.

It could be that your rewriterule is too strict - you use a $ at the end of thank-you-item.html, which indicates END-OF-URL.  That means a request like /whatever/thank-you-item.html?id=4 will not match that rule.  If you would like that rule to allow an optional query string, then you'll need to adjust it.  something like

# RewriteRule ^/thank-you-item.html$ /category1.asp?category=ct [L]
RewriteRule ^/thank-you-item.html(\?.*)?$ /category1.asp?category=ct [L,QSA]

And as you can see I've used QSA there to append any query string to the replacement URL. That way the category.asp page will get whatever is present in the initial URL.


If the above isn't helpful, well, as I said, I'm not quite clear on what you're doing. Here's what would help me to understand: Post the 3 or 4 rules you use. Describe the requests you submit, whether you use GET/POST and  exactly the URL you use;  also describe the results you expect to see, and the actual results you observe. 

When you describe the expected and actual results, that should include 301 and 302 responses, if appropriate, complete with actual URLs that get sent to the browser.  Also then also the results of submitting that new URL back to the server.

I know YOU understand your situation, but I don't. I can offer more help if you are very clear and basic in your descriptions.

I see you have some rules and URLs that work as expected.  I think there is at least one URL that does not work as expected.  I don't know exactly what your expectations are. I don't clearly see how the results you are seeing, differ from the expectations.

Apr 27, 2010 at 3:08 AM

I will post the matrix soon, so you clearly get the idea on what we would like to achieve.

Apr 28, 2010 at 2:24 AM

For example:

RewriteCond %{SERVER_NAME} ^www\.mydomain\.com$ [I]
RedirectRule ^/category\.asp\?category=ct http://www.mydomain.com/thank-you-item.html [QSA,I,R=301]

This means any URL request from the browser by the end-user will result in returning status 301 with quersystring parameter being passed to the HTML page. So if for every request by the end-user irrespective of the querystring parameter will result in 301.

Thinking more about it, why would someone want to do that, since the thank-you-item.html is a virtual page, that has a Rewrite rule to forward further.

Not sure this is my unique requirement, but the reason we want to do 301 for all request to category=ct&(any number of querystring) - is due to search engines not considering that as a duplicate content. By adding QSA that defeats the purpose.

If i were to achieve above, how would i do it with ISAPI filter.

** Since we implemented six months ago, this was working fine, passing in the values even though we had $ at the end. Somehow due to the patch or some update it has stopped working. This is just for your FYI.

Thanks,

Coordinator
Apr 28, 2010 at 3:23 AM

I'm sorry, I'm not following.

bhaktavatsal wrote:

For example:

RewriteCond %{SERVER_NAME} ^www\.mydomain\.com$ [I]
RedirectRule ^/category\.asp\?category=ct http://www.mydomain.com/thank-you-item.html [QSA,I,R=301]

This means any URL request from the browser by the end-user will result in returning status 301 with quersystring parameter being passed to the HTML page. So if for every request by the end-user irrespective of the querystring parameter will result in 301.

No. I disagree with your English-language translation of that rule. I'm also having trouble with your syntax. "So if for every..."

In English, the above rule says:  any incoming URL request to /category.asp, where the querystring begins with category=ct, will be redirected with HTTP status code 301.  The full input query string (beginning with category=ct, and possibly including other parameters) will be appended to the redirect target, http://www.mydomain.com/thank-you-item.html . This applies only when the SERVER_NAME is www.mydomain.com.

Thinking more about it, why would someone want to do that, since the thank-you-item.html is a virtual page, that has a Rewrite rule to forward further.

Not sure this is my unique requirement, but the reason we want to do 301 for all request to category=ct&(any number of querystring) - is due to search engines not considering that as a duplicate content. By adding QSA that defeats the purpose.

If i were to achieve above, how would i do it with ISAPI filter.

** Since we implemented six months ago, this was working fine, passing in the values even though we had $ at the end. Somehow due to the patch or some update it has stopped working. This is just for your FYI.

Thanks,

I don't follow this part either. It seems like you are asking me why you want to use the rules you are using. These are your rules we are discussing, right? So I can't answer why you use them.

I'm sure I'm misunderstanding something here.

Apr 28, 2010 at 6:50 PM

I will think about it and will let you know, but at the heart of the issue is reading other parameters including category=ct without 301. Issue with not doing 301 for that redirect is the duplicate content by the search engines. I will post more information shortly to precisely specify what is the issue i am seeing with this redirects and i am sure not the only one who want to do this.

Thanks,