Adding a dot (.)

Topics: Developer Forum, Project Management Forum, User Forum
Nov 3, 2010 at 3:19 PM

Hi,

I am trying to edit the RewriteRule in such way it accept dot (.) but when making so the style of the website is breaking

here is the original ini file:

RewriteRule ^/?$     /Default.aspx  [L]
RewriteRule  ^/([^\.]*)$  /Page.aspx?urlTerm=$1

I was trying to do this (but it breaking the css style):

RewriteRule ^/?$     /Default.aspx  [L]
RewriteRule  ^/([^\.].*)$  /Page.aspx?urlTerm=$1   ==> pay attention to the dot I added before the *

Please advise me how to solve this,

Thanks.

Coordinator
Nov 4, 2010 at 1:44 AM
Edited Nov 7, 2010 at 1:50 PM

I'm not clear on what you're intending to do.

You wrote that you are trying to modify a rule in such a way that it accepts a dot.  That sounds simple enough, but yet, it is not clear just where you would like to accept a dot.  Anywhere?  Would you like to accept a pattern with only dots?  What if the incoming URL consists of only a single dot?  Should that also be passed by your prospective rule?

So you see, it is simple to say "I want to accept a dot", but as far as text pattern matching, your statement is not clear or complete at all.

Ok, now the second issue here is that the dot itself is a meaningful character for regular expressions.  It's a wildcard. It matches "any character". So, if you want to actually match a dot, then you must escape the dot in the regex.  This is explained in the section of the IIRF documentation that covers how to apply regex to URLs.

Last, I suggest that you try an interactive regex tool, to try out your regex against various URLs.  I suggest several of these in the IIRF documentation. They are excellent learning tools, and will give you good insight into how to set up your regex so that it does what you want.

Nov 4, 2010 at 9:08 AM

Thank you for your reply,

I will try to clarify: 

I am using the RewriteRule       (RewriteRule  ^/([^\.]*)$  /Page.aspx?urlTerm=$1)       to create friendly URLs. for example:

For the URL "www.mysite.com/somepage" , the RewriteRule sends to my application  "www.mysite.com/page.aspx?urlTerm=sompage" in such way I can use the query string to retrieve from the DB the page 'somepage'. now I need to allow using email as parameter: www.mysite.com/somepage?a=email.a@gmail.com - now the Isapi filter should pass to my application- www.mysite.com/page.aspx?urlTerm=soomepage?a=email.a@gmail.com.

I was using a tool the test my regx and I succeed (only in the tool) but I guess I'm missing something.

I really hope I made my self clear this time.

Thanks.

 

here is my ini file:

RewriteRule ^/?$     /Default.aspx  [L]
RewriteRule   ^/([^\.]*)$  /Page.aspx?urlTerm=$1

 

 

 

 

 

 

Coordinator
Nov 7, 2010 at 2:12 PM
Edited Nov 7, 2010 at 2:17 PM

yes, I think I've understood this time.  Except, your second post here, seems completely unrelated to the first.  In the second post, you don't talk about adding a dot, at all.  I'm not sure where the "Adding a dot" part comes in. Maybe you no longer want to add a dot.  The thing you described in your second post is processing the query string.

There's a modifier in IIRF, [QSA] that is designed to assist in this. QSA stands for query-string-append. You can read about it in the IIRF documentation, and see some examples. Basically: any query string in the original URL is appended to the query string, if any, in the rewritten URL.

Using this, you will want to remove the $ terminator from the pattern, because that indicates "end of line" and it means you would capture the query string in addition to the url path in the $1.  You will also want to replace the \. with a \? .  What this does is say "any sequence of characters that does not include a question mark".  This will capture everything in the url path up to the query string, if any, in the original URL.  The modified rule looks like this:

RewriteRule   ^/([^\?]*)  /Page.aspx?urlTerm=$1  [QSA,L]

Using this, if the user requests www.mysite.com/somepage?email=foo@bar.com , then you will get somepage in $1, and the query string in the original is appended to the rewritten URL, which is  /Page.aspx?urlTerm=somepage&email=foo@bar.com .  It is not legal to include more than one unescaped ? in the URL, so your example where there are two, is not possible.  Doing it the way I suggest will give you what you expect in your Request.Params array inside the ASPNET page.   You will need to use the [L] modifier also, to prevent iteration on that rule. I'm not sure why you were excluding the dot in the original pattern. If you really want to do that, you should use both \. and \? in the pattern.

Good luck.

 

Nov 7, 2010 at 3:15 PM

Thank you very much for your help!

The rule is working but the Style.css is not accessible anymore, do you have an idea why?

 

Eyal.

 

 

 

 

Coordinator
Nov 7, 2010 at 5:25 PM

probably because www.mysite.com/Style.css gets rewritten to www.mysite.com/Page.aspx?urlTerm=Style.css .

Why do you not simply exclude .css files from the rewrites, like so:

RewriteRule  ^/.*\.css$  - [L]

if you also have .gif, .jpg, and so on, add those to the exclusion list, like so:

RewriteRule  ^/.*\.(css|jpg|gif)$  - [L]

If you want a case-insensitive exclusion, do this:

# Exclude files with these extensions from rewrite: .css, .jpg, .gif
RewriteRule  ^/.*\.(css|jpg|gif)$  - [L,I]

Put this rule before the rule that does the search-engine-friendly rewrites. Include the comment to remind yourself what it does.