ASP/VBSCRIPT URL Trailing dots issue - iis-7

i've got a problem whereby some websites linking into mine have truncated the URL with trailing dots, 3 of them to be exact!
eg. http://www.mywebsite.com/7542-this-is-a-link-to...
The url should be http://www.mywebsite.com/7542-this-is-a-link-to-my-website.html
Naturally, ISAPI rewrite doesn't understand the truncated url so I need to do a redirect to the correct url using a 301 redirect
Something like:
RewriteRule ^7542-this-is-a-link-to... /7542-this-is-a-link-to-my-website.html [L,R=301]
But for the life of me I cannot get ISAPI rewrite to match against the 3 dots, annoyingly the incorrect URL doesn't even 404 redirect! I have no idea where it is going to... Just a blank screen so am guessing it has something to do with IIS web.config file...
Please help me before I become balder than I already am!

The could be several different reasons for that. Basically the rule like:
RewriteRule ^7542-this-is-a-link-to.* /7542-this-is-a-link-to-my-website.html [L,R=301]
would fix the problem, matching everything after "-to". But it's not ISAPI_Rewrite that throws 404. It's IIS. I had issues before and all googling ended up with IIS blocking suspicious characters. Try to tweak that.
It could be this "dots in the URL"
This thread has a lot of useful info

I'm totally ignorant of Microsoft internet tech, but is there any chance that the three dots in the incoming URL are actually a single "ellipsis" character (… not ...)? If so, you'd need to use that character in your RewriteRule. You'd have to check the docs to know how to correctly encode that character for the config file.

Related

Modify regex to more selective

Using urlrewriting on a website that also has a blog, however I have found an issue with conflicting rules.
I think can be resolved by simply modifying the regex in the offending rule to eliminate the blog pages, but I've not yet been able to get it to work.
Here's the issue that's causing the problem:
www.mysite.com <== my site
www.mysite.com/blog/... <== root of blog
At the moment, the regex is simply "(.*)/$", which is actionable on all pages.
However, it obviously picks up the blog pages. The blog has a slightly different setup which causes issues when I apply the rule, so I'm looking to be able to select the main site pages, but not anything that has the /blog/ directory in its structure.
Anyone help me convert the regex pattern to exclude what I need - I've tried so many permutations - its now causing issues, as our SEO is broken, and its very difficult to test over on the live system.
The elegance of the regex used depends on the power of the regex engine which in turn depends on the environment your regex is used in.
Basic
Works with any engine since it only uses basic operators.
Write
^www.mysite.com($|/$|(/([^b]|b[^l]|bl[^o]|blo[^g]|blog[^/])).*)/$
or for general domains (not advisable imho)
^[^/]+($|/$|(/([^b]|b[^l]|bl[^o]|blo[^g]|blog[^/])).*)/$
Negative Lookahead
Patterns may be specified contingent on non-occurrence of entire strings after a particular position within a match.
^(www.mysite.com(?!/blog/).*)$
For more details on lookahead ( and the similar concept of lookbehind ) see this part of a resource on regular expressions engines and the concepts behind.
Web Server URL Rewriting
If the execution context is a URL rewrite module, you may exploit rule ordering, special processing directives and flags to simplify the regexen. Aside from peculiarities of the syntax, the general ideas of the samples should be implementable in any decent Url rewriting plugin.
Microsoft URL Rewriting module for IIS
(Note: The content of this section reflects MS documentation only.)
There is a tutorial on how to specify Rewriting rules in IIS. As authoritative source for the available regex syntax,the ECMA-262 standard is given (basically that's JavaScript - so lookahead should be available).
Thus in the web.config configuration file, the rewrite section should look like:
<rewrite>
<rules>
<rule name="Whatever description fits">
<match url="^(www.mysite.com(?!/blog/).*)$" />
<action type="Rewrite" url="example.com/whatever" />
</rule>
</rules>
</rewrite>
Apache mod_rewrite and compatible
The following sample addresses your problem for Apache 2.4/mod_rewrite and IIS/IIS-Mod-Rewrite.
(Note: The website of the IIS plugin claims to be 100% mod_rewrite compatible. I do not know whether that claim is correct.):
RewriteRule ^(www.mysite.com/blog/.*)$ $0 [S=1]
RewriteRule ^(.*)$ ...
where ... represents the rewritten url plus any applicable flags. The first rule leaves a matched blog url unchanged and due to the skip flag ([S=1]) ignores the next rewriting rule.
You might also wish to look at the ENDflag and the RewriteCond directive.
Reference: Apache Docs ( Apache httpd 2.4: mod_rewrite )

Regex on URL rewrite module

I need a help with Regex on URL rewrite module.
I want to apply a rule for the home page.
I tried with ^default.aspx, which is working fine when user access the site with /default.aspx
But normally users are accessing the site with / (www.website.com/) so I am trying to write the reqex and not able to find the correct one.
I tried lot of different combination but nothing worked so far.
^(/default.aspx|$|/$)
^(|/|/default.aspx)
Thanks for the help
You could use the following pattern:
^(/|default.aspx)?$
It will match /, default.aspx or nothing

IIS7 Rewrite Module - Redirct from root to default.aspx

I have a situation where I need to rewrite from the root to default.aspx. So if someone hits www.domain.com or www.domain.com/ I need to redirect to www.domain.com/default.aspx - any idea what the regex for this looks like and which server variable to regex on?
When I run a trace and I visit www.domain.com/ or www.domain.com it always shows the SCRIPT_NAME and other similar server variables to have a value of /default.aspx - however this does not work in the rewrite module. E.g. when someone visits www.domain.com/ or www.domain.com the SCRIPT_NAME is still /default.aspx - so it doesn't seem to pick up that they visited the non default.aspx page.
I solved this by using a Url Rewrite map (part of the rewrite module), I was able to redirect from / to /default.aspx. As a rule before the rewrite map I make sure that all requests are redirected to an ending slash.
I had a similar problem and I think it really sucks that IIS hides the URL from you and only gives you the name of the script, which you already know. It was worse in earlier versions of IIS, because it forgot to copy the query string. I had to work around that by not defining any default document at all, and making the error page for directory listing denied redirect to the script. I guess the same thing would work here.

Response.Redirect passes the ISAPI_Rewrite engine

*I use ISAPI_Rewrite v2
Hi,
So I implement ISAPI_Rewrite on my site.
Now i put on my pages a Response.Redirect
But as it seems the redirect passes the ISAPI engine..
i.e. I see the new url but the rule doesnt apply.
for example i enter this:
example.com/SomePage.aspx
in SomePage.aspx.cs - PageLoad function theres:
Response.Redirect("/Page");
So I get redirected to example.com/Page
But it says to me "This link appears to be broken"
on httpd.ini I have this rule
RewriteRule ^/Page$ /Page.aspx [L]
My guess is that the Response.Redirect doesnt go through
the ISAPI_Rewrite...
How can I fix this??
Thanks
=====
edit:
solved, the hebrew chars was the problem, you need to encode them first.
if you do response.redirect the whole page life cycle is working. All the modules are called as usual. So maybe the rewrite module does not get called?
Did you put some breakpoints in the module so that you know if it gets called or not?
have you set up your module somewhere in your webapp?

Extensionless url rewriting / filtering url rewrites

I've done some url rewriting, always using the Intelligencia.UrlRewriter and it always worked fine. But now i want to achieve the following and somehow i can't get it right.
i want:
www.mydomain.com/products/books > rewrite to www.mydomain.com/products.aspx?id=books
this works fine, because i can set my criteria to /products/..
www.mydomain.com/mybook > rewrite to www.mydomain.com/productdetails.aspx?id=mybook
and of course i want www.mydomain.com/newbooks.aspx to function normally
and these last 2 don't work together.
is there a way i can tell my rewrite rule to only rewrite when there is no extension in my url? or is there an other trick?
Thanks in advance!
Well, a bit off the road, but try using ASP.NET Routing instead of URL Rewriter.
I was playing (and messing up) with the rewriter, and here on Stackoverflow I was advised to use Routing, and it is MUCH better (and easier when you get it).
You'll need some little changes to your ASPX files though, but very small.
I thought i'd solve this old, unanswered question. The problem with the extensionless urls turned out to be some configuration problem in IIS. Our system admin fixed this by allowing these urls and after that the rewriter had no problems picking up and translating the URLS.

Resources