AJAX Not working and Subdomain with IIRF

Jun 22, 2008 at 5:22 AM
Edited Jun 23, 2008 at 2:43 PM
Hello,

I was working on a few different things.

1. How do I get the subdomain www to pop in if one is not specified. Here are my rules:

These two work great:

RewriteRule ^(.*)/(home)\.(aspx)$ $1/ [I,R=301]
RewriteRule ^/([^\.\/\?]+)$  /files/details.aspx/$1  [L]

With the subdomain, I want to be able to still pass a parameter after the URL that I handle above.
My goal is that:
http://site1.com/parameter would be http://www.site1.com/files/details.aspx/parameter

I tried some things including this, but it doesn't work right:
RewriteCond %{HTTP_HOST} ^(?!http?://(?:www\.)site1\.com/)   [I]
RewriteRule ^/(.*) http://www.site1.com/$1 [I,R=301] [L]

2. In regards to ASP.Net AJAX, it gets messed up with the filter. The fix is you are
supposed to not use the filter when the request header "X-MicrosoftAjax: Delta=true".
How would we get the request header and check for that?

3. Is it possible to rewrite the entire URL to lowercase if any part is not lowercase?
I see how to do sections, but how to you check and do the entire URL?


Thank you!

Coordinator
Jun 23, 2008 at 6:51 PM
Edited Jul 1, 2008 at 6:16 PM
1. "How do I get the subdomain www to pop in if one is not specified?"

I think it works best if we are careful and specific with words.  I don't know what you mean by "pop in". 
I think what you want is to redirect a request to a different domain name. 

You've told me that you tried things. And you've said they didn't work.  But I don't know what you expect, exactly, and I don't know what you're getting.  I know you're not happy, so I an guessing the "what you expect" does not match "what you are getting".  But beyond that, I would be guessing.  I'm not trying to be difficult.  I know these discussions are hard to have over a forum.  If you can be more specific, and more precise with your words, I'll be able to help you better.

I THINK that maybe you want all requests directed to http://site.com to be redirected to http://www.site.com .  I believe you also want to Rewrite URLs.   Those sound like reasonable goals. It also seems reasonable to handle these different goals with different rules.  

The Redirect - I think you know how to do that, with a R=301 redirect.   This is a Redirect.  Can you perhaps handle the redirect by itself, in a distinct rule.  This might be something like
RewriteCond %{HTTP_HOST}  ^(?!www\.site1\.com).+$   [I]
RewriteRule ^/(.*) http://www.site1.com/$1 [I,R=301] [L]

The HTTP_HOST variable never includes the http prefix and never includes the trailing slash. HTTP_HOST is the hostname, not decorated with that other stuff. Your regular expression included both, and so I suppose it would NEVER match. (If you checked the logfiles you would have been able to see what HTTP_HOST evaluates to, and you may have been able to figure that out yourself.)

Next thing - on the redirect, I think we discussed this separately.  I am not clear what more you need here.

2. The filter does not query arbitrary headers by name. But you can match on ALL_RAW, which is a single server variable that aggregates all headers.  Do a matcch on ALL_RAW for X-MicrosoftAjax and then you'll know if ASP.NET Ajax is is in use.


3. you've seen the doc on the case-folding flags ?    #L #U #E #l #u
You can do just bracket any Replacement string with #L/#U and it will lowercase everything.

So...

RewriteRule ^/([^\.\/\?]+)$ /#Lfiles/details.aspx/$1#U  [L]

Jul 1, 2008 at 5:47 PM
Edited Jul 1, 2008 at 5:50 PM
Hey Cheeso,
Thank you for the information!
I will try and be more clear b/c I need to handle a few scenarios and it's tough.

When you said:
RewriteCond %{HTTP_HOST}  ^(?!www\.site1\.com).+$   [I]
RewriteRule ^/(.*) http://www.site1.com/$1 [I,R=301] [L]








That is correct.
If someone inputs http://site1.com I would like it to become http://www.site1.com.
BUT also if someone inputs http://site1.com/myfolder/hey.aspx I would like it to become http://www.site1.com/myfolder/hey.aspx
BUT if the user inputs something after the home URL with no www and no "." on the end, i.e.- http://site1.com/hey I would like it to become http://www.site1.com/hey
while pointing to the real page of http://www.site1.com/folder1/page.aspx/hey Finally, if possible also make what
ever URL was typed in, the entire thing to be lower case, meaning http://site1.com/FOLDER1/Folder2/Page2 > http://www.site1.com/folder1/folder2/page2




So to Review:
http://site1.com > http://www.site1.com
http://site1.com/hello > http://www.site1.com/hello (b/c there is no extension) but points to http://www.site1.com/folder1/page.aspx/hello
http://site1.com/folder1/page.aspx > http://www.site1/folder1/page.aspx (has extension or query string) 
http://site1.com/FOLDER1/Folder2/FOLDER3/page.aspx >> http://www.site1.com/folder1/folder2/folder3/page.aspx (make whatever the URL is to all lowercase)

Also, can you provide an example to help solve for below? I'm lost. I want the filter to disable for X-MicrosoftAjax:
2. The filter does not query arbitrary headers by name. But you can match on ALL_RAW, which is a single server variable that aggregates all headers. 
Do a matcch on ALL_RAW for X-MicrosoftAjax and then you'll know if ASP.NET Ajax is is in use.

Thank you!!!




Cheeso wrote:
1. "How do I get the subdomain www to pop in if one is not specified?"

I think it works best if we are careful and specific with words.  I don't know what you mean by "pop in". 
I think what you want is to redirect a request to a different domain name. 

You've told me that you tried things. And you've said they didn't work.  But I don't know what you expect, exactly, and I don't know what you're getting.  I know you're not happy, so I an guessing the "what you expect" does not match "what you are getting".  But beyond that, I would be guessing.  I'm not trying to be difficult.  I know these discussions are hard to have over a forum.  If you can be more specific, and more precise with your words, I'll be able to help you better.

I THINK that maybe you want all requests directed to http://site.com to be redirected to http://www.site.com .  I believe you also want to Rewrite URLs.   Those sound like reasonable goals. It also seems reasonable to handle these different goals with different rules.  

The Redirect - I think you know how to do that, with a R=301 redirect.   This is a Redirect.  Can you perhaps handle the redirect by itself, in a distinct rule.  This might be something like
RewriteCond %{HTTP_HOST}  ^(?!www\.site1\.com).+$   [I]
RewriteRule ^/(.*) http://www.site1.com/$1 [I,R=301] [L]

The HTTP_HOST variable never includes the http prefix and never includes the trailing slash. HTTP_HOST is the hostname, not decorated with that other stuff. Your regular expression included both, and so I suppose it would NEVER match. (If you checked the logfiles you would have been able to see what HTTP_HOST evaluates to, and you may have been able to figure that out yourself.)

Next thing - on the redirect, I think we discussed this separately.  I am not clear what more you need here.

2. The filter does not query arbitrary headers by name. But you can match on ALL_RAW, which is a single server variable that aggregates all headers.  Do a matcch on ALL_RAW for X-MicrosoftAjax and then you'll know if ASP.NET Ajax is is in use.


3. you've seen the doc on the case-folding flags ?    #L #U #E #l #u
You can do just bracket any Replacement string with #L/#U and it will lowercase everything.

So...

RewriteRule ^/([^\.\/\?]+)RADEDITORFORMATTED_1nbsp; /#Lfiles/details.aspx/$1#U  [L]




Coordinator
Jul 1, 2008 at 6:27 PM

Hey Neo, I understand you have lots of goals.

I recommend that you break them down into parts, and accomplish one thing at a time.

For example, a rule to perform redirects  for URL requests that lack the www.  I gave you that.  Does it work?  Does it do what you want?

Beyond redirects, you want to rewrite URLs.  You can rewrite the URLs after they have been rewritten.  So that, for example, you can rewrite from http://www.site1.com/hello to http://www.site1.com/folder1/page.aspx/hello. There are tons of examples for that sort of thing.

Finally, you want to lowercase things - I am not sure if you want the lowercase part to show up in the browser address bar or not, but I think you do. If you do, then it is a REDIRECT, not a REWRITE. And I showed you how to do that.

The last thing is to match on Ajax in the ALL_RAW Server variable. This would be something like so:

# Null Rewrite if MicrosoftAjax is in use.  (Rewrite the url to itself, and Make this the last rewrite rule, so no more rewrites on this request). 
RewriteCond %{ALL_RAW}  X-MicrosoftAjax   
RewriteRule  ^(.*)$  $1 [L]

You said you want the filter to disable if Microsoft Ajax is in use. You can't really disable the filter, but you can rewrite the request without a change, and mark it as the last rewrite. That should accomplish what you want. Make the above rule the first one in your ini file.

Jul 1, 2008 at 8:09 PM
Hey Chesso,
Thanks for the information again!!!

When you said:
http://www.site1.com/hello to http://www.site1.com/folder1/page.aspx/hello

I'm looking for http://site1.com/hello < (missing subdomain and has no extention) to become
http://www.site1.com/hello (now has subdomain, I also want this URL to the left to show in the address bar)
but is rewriting for http://www.site1.com/folder1/page.aspx/hello (this URL is the actual application page referenced, but not shown in the address bar.)

Is that possible?

Thank You!!!


Cheeso wrote:

Hey Neo, I understand you have lots of goals.

I recommend that you break them down into parts, and accomplish one thing at a time.

For example, a rule to perform redirects  for URL requests that lack the www.  I gave you that.  Does it work?  Does it do what you want?

Beyond redirects, you want to rewrite URLs.  You can rewrite the URLs after they have been rewritten.  So that, for example, you can rewrite from http://www.site1.com/hello to http://www.site1.com/folder1/page.aspx/hello. There are tons of examples for that sort of thing.

Finally, you want to lowercase things - I am not sure if you want the lowercase part to show up in the browser address bar or not, but I think you do. If you do, then it is a REDIRECT, not a REWRITE. And I showed you how to do that.

The last thing is to match on Ajax in the ALL_RAW Server variable. This would be something like so:

# Null Rewrite if MicrosoftAjax is in use.  (Rewrite the url to itself, and Make this the last rewrite rule, so no more rewrites on this request). 
RewriteCond %{ALL_RAW}  X-MicrosoftAjax   
RewriteRule  ^(.*)$  $1 [L]

You said you want the filter to disable if Microsoft Ajax is in use. You can't really disable the filter, but you can rewrite the request without a change, and mark it as the last rewrite. That should accomplish what you want. Make the above rule the first one in your ini file.




Coordinator
Jul 2, 2008 at 6:31 AM
Edited Jul 2, 2008 at 6:38 AM

are we going round in circles?

YES, what you ask for is possible. I think you need two rules: one for redirect and another for rewrite.  In my previous message I told you that I already gave you the redirect rule. The rewrite rule is simple, if you can follow the examples.

Does that make sense?

What have you tried?
What results do you see?

I think you are begging me to do this FOR YOU. Look, I don't know the answer. You have to be able to figure this out yourself. I can write rules but I don't know if they do what you really want. You need to be in charge of that. A little knowledge is dangerous! You need to be comfortable enough with this rewrite thing that you know it will work the way you want. Being comfortable with it is much better, trust me on this, much better than just getting a magic regex incantation and it sort of works but you're not really sure how.

Start with this?

# Null Rewrite if MicrosoftAjax is in use.  (Rewrite the url to itself, and Make this the last rewrite rule, so no more rewrites on this request). 
RewriteCond %{ALL_RAW}  X-MicrosoftAjax   
RewriteRule  ^(.*)$  $1 [L]

# Redirect for bad site name
RewriteCond %{HTTP_HOST}  ^(?!www\.site1\.com).+$   [I]
RewriteRule ^/(.*) http://www.site1.com/$1 [I,R=301]

# Rewrite for all other URLs (and do case folding)
RewriteRule ^/([^\.\/\?]+)$  /#Lfiles/details.aspx/$1#U  [L]

Jul 2, 2008 at 3:04 PM
Edited Jul 2, 2008 at 3:05 PM
Hey Cheeso,

I wanted to make sure you understood what I was asking so I didn't spend a ton of time on it if would not be possible.
I am super busy and I know you are. I thought I was trying to do something kind of funky that needs to handle a combination of things that
I didn't see an example for. I wanted to make sure I was not going to waste a whole bunch of time I don't have trying to figure it out.
You are the expert at this so I was hoping you would know off the top of your head (as you did).

Thanks



Cheeso wrote:

are we going round in circles?

YES, what you ask for is possible. I think you need two rules: one for redirect and another for rewrite.  In my previous message I told you that I already gave you the redirect rule. The rewrite rule is simple, if you can follow the examples.

Does that make sense?

What have you tried?
What results do you see?

I think you are begging me to do this FOR YOU. Look, I don't know the answer. You have to be able to figure this out yourself. I can write rules but I don't know if they do what you really want. You need to be in charge of that. A little knowledge is dangerous! You need to be comfortable enough with this rewrite thing that you know it will work the way you want. Being comfortable with it is much better, trust me on this, much better than just getting a magic regex incantation and it sort of works but you're not really sure how.

Start with this?

# Null Rewrite if MicrosoftAjax is in use.  (Rewrite the url to itself, and Make this the last rewrite rule, so no more rewrites on this request). 
RewriteCond %{ALL_RAW}  X-MicrosoftAjax   
RewriteRule  ^(.*)$  $1 [L]

# Redirect for bad site name
RewriteCond %{HTTP_HOST}  ^(?!www\.site1\.com).+$   [I]
RewriteRule ^/(.*) http://www.site1.com/$1 [I,R=301]

# Rewrite for all other URLs (and do case folding)
RewriteRule ^/([^\.\/\?]+)$  /#Lfiles/details.aspx/$1#U  [L]