Sub-Domain URL Rewrite Issues - iis

I have been scratching my head with this problem for at least two months. I have a classified ads section in our site which has SEO friendly URL's I want to rewrite these url's. I am not sure if the problem is related to the subdomain for each region. The URL may look like this:
These are working URL's:
http://milwaukee.storeboard.com/classifieds/for-sale/business/make-incredible-income-while-growing-your-local-economy/425
I want to make it goto this address on our server:
http://milwaukee.storeboard.com/classifieds/viewad.asp?ClassAdID=425
I am using the following code in the web.config file... but no matter what variations I try I cant get it to work..
<rule name="Classifieds Ad" stopProcessing="true">
<match url="^http://([^/]+)/classifieds/.*?(\d+)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="http://{R:1}/classifieds/viewad.asp?ClassAdID={R:2}" />
The only reason the first link works at this time is because I am using my 404 error page to process the request and then calling the page via MSXML2.ServerXMLHTTP.6.0 but this is unreliable and can timeout, especially during times of heavy usage. I want to remove this method and use the quick IIS URL Rewrite.
I would really appreciate any help you can provide

Try the below rule
<rule name="Classifieds Ad" stopProcessing="true">
<match url="^classifieds/.*?/(\d+)$" />
<conditions>
<add input="{HTTP_HOST}" type=”Pattern” pattern="^(.*)$">
</conditions>
<action type="Rewrite" url="{C:0}/classifieds/viewad.asp?ClassAdID={R:1}" />

Related

Show default document extension in URL

I've been given several requests to rewrite a URL in IIS. One of them includes having the .html page as part of the URL, but without the HTML tag. For example, www.foo.com/bar.html would be displayed as www.foo.com/bar instead. I have this rule to accomplish that and it seems to work ok.
<rule name="Hide .html ext" enabled="true">
<match url="^(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}.html" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:0}.html" />
</rule>
The problem I'm having is that since index.html is a default document in IIS, so www.foo.com never shows index.html for my html rewrite rule to handle it (at least that is my assumption as to what is happening). This is the same if the page is something like www.foo.com/bar/index.html. They would want www.foo.com/bar to redirect to www.foo.com/bar/index in the URL.
Essentially is it possible to somehow force the default document to show? I've been attempting all sorts of strange scenarios using {PATH_INFO}, {URL}, and {PATH_TRANSLATED} to somehow attempt to catch any index.html page to rewrite it "correctly" in the URL.
Example attempt that I know is in the wrong direction:
<rule name="Include /index" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{PATH_INFO}" pattern="(.+?(?=(index.html|\/index.html|\/index.html\/)$)|^(index.html))" />
<add input="{URL}" pattern="(.+?(?=(index|\/index|\/index\/)$)|^((index)|(\/index\/)))" negate="true" />
</conditions>
<action type="Redirect" url="/index" appendQueryString="false" redirectType="Permanent" />
</rule>
I feel like I'm overthinking this and there's possibly a simpler solution that uses IIS URL rewrite.
If the default document function is enabled, the index cannot be displayed in the URL, including index.html.
If you want to display the index in the url unless manually enter it in the browser. There are some problems with URL rewriting. Even if the URI is empty, the request is sent to IIS, and what is received in IIS is the URL with farvicon.ico attached. In URL rewriting, it is not very accurate to determine whether the URI is empty.

Why are URL rewrites in Azure Web App virtual directory not being processed when root directory contains rewrites?

I have two virtual directories in an Azure Web App and confirmed that they're working properly as application directories.
The root of the Web App contains nothing except a web.config file with two rewrite rules that cause subdomains to point to subfolders like this:
<rule name="App1 Subdomain Redirect to SubFolder">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^app1.myservice\.net$" />
</conditions>
<action type="Rewrite" url="/app1/{R:0}" />
</rule>
<rule name="App2 Subdomain Redirect to SubFolder">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^app2.myservice\.net$" />
</conditions>
<action type="Rewrite" url="/app2/{R:0}" />
</rule>
(I understand this could be written more efficiently - I'm trying to remove as many variables as possible.)
In each of the virtual directories I have another web.config that contains a single rule to add an extension:
<rule name="Add Extension">
<match url=".*" negate="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.ashx" />
</rule>
The problem I'm experiencing is that the "Add Extension" rule is never processed.
If I remove the rule from the virtual directory's config file and put it into the root's, all is well. (If I only do this for one virtual directory, it works fine for that directory while the other does not. If I do it for both, then all rules get processed.)
If I remove the "Add Extension" rule and try other rules the other rules do not get processed, which indicates to me this is not a problem specific to this particular rule.
If I remove all rules from the root's config, all rules in the virtual directories get processed.
My question is, has anyone else experienced this and what have they done as a workaround?
It's my understanding that rules should cascade from root to virtual directories in the same way other configuration settings do.
Searches have not been helpful.
Anand seems to have experienced the same problem on a non-Azure IIS site but no answer was proposed: http://forums.iis.net/t/1178488.aspx
Zielu1's question is somewhat similar but again did not receive a response: IIS URL rewrite in child virtual directory not redirecting
There are a fair number of other questions about rewrites, mostly about syntax and getting them to work in general, but few about virtual directory inheritance of rules.
Thanks for the help.
Try it matching full subdirectory paths
<rule name="Add Extension">
<match url="/MySubDirectory/.*" negate="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.ashx" />
</rule>

Hide page extension and table names in url

How do i hide my page extension for example
mysite.com/index.asp
how do i take off the extension .asp
and also how i hide tables field names in a URL. example is I'm displaying details of a record of 2 . so the link is going to be
mysite.com/details?record_id=2
how do i take off the record_1d=2 to make it
mysite.com/details
I'm working with asp classic.
thanks
You want this:
http://www.iis.net/downloads/microsoft/url-rewrite
Your rule would look like this:
<rewrite>
<rules>
<rule name="RewriteASP">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.asp" />
</rule>
</rules>
</rewrite>
As far as I'm aware you can't rewrite the querystrings without retooling your code to pass data via HTTP posts.

Setting up URL Rewrite rule for a specific domain

For local dev testing, I need to catch all requests to www.somedomain.com/XXX (where X is the path), and send them on to localhost/somevdir/XXX.
I've added this to my HOSTS file (c:\windows\system32\drivers\etc):
127.0.0.1 www.mydomain.com
Then, in IIS8 (Windows 8), I've added a binding to my "Default Web Site" for the host www.mydomain.com. This works, I can now browse www.mydomain.com/test.html and see a test html page. My virtual dir is inside the Default web site. I then add a URL Rewrite URL to the web site for the last bit:
<rewrite>
<rules>
<rule name="mydomain.com" stopProcessing="true">
<match url="^www.mydomain.com/(.*)" />
<action type="Rewrite" url="localhost/MyVDir/{R:1}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
But - that doesn't work. I get a 404 so it looks the the match never happens. I've tried redirect and rewrite, and I've tried without the ^ in the regex and a few other regex tweaks. Can someone explain what I've done wrong?
I think the following should work:
<rule name="mydomain.com" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(mydomain\.com|www\.mydomain\.com)$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="http://localhost/MyVDir/{R:1}" redirectType="Temporary" />
</rule>
The match on any URL makes sure the conditions are checked, and the HTTP_HOST server variable seems the most reliable way of checking the requested hostname. You could remove the REQUEST_FILENAME input condition, but it works as quite a nice sanity check to make sure static files are always served.
The following is better for catching both www. and non-www. versions of the domain so that you don't have to write the domain twice, which could possibly cause errors with being twice as likely to write a typo. (The parenthesis with the ? character means optional in regex terms.)
<rule name="mydomain.com" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(www.)?mydomain\.com$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="http://localhost/MyVDir/{R:1}" redirectType="Temporary" />
</rule>

301 redirects with Joomla on IIS

I'm running Joomla on IIS. I've got about a dozen categories (financial newsletter publishers) that I'm using to organize about 40 articles (financial newsletters). I'm using the joomla built-in SEO so the URL's look like this:
http://www.global-autotrading.com/autotraded-newsletters/13-angel-publishing/43-options-trading-pit.html
The numbers in front of the categories and articles are annoying, and I'm not too fond of the navigation provided by a Section Layout menu item. Also, some financial newsletters don't operate under the umbrella of a publisher so I want a more flexible organization.
I've tried simply constructing a menu hierarchy (under the autotraded newsletters menu) that has some newsletters directly under the parent menu item, and some publishers with their newsletters as menu items underneath them. However, that was causing some links to break; clicking on a link would take me to the wrong article, and what not. Thus, it seems like using a hand-coded menu structure is not compatible with using another, "parallel" section-layout view of the content.
Thus, I've decided to get rid of the idea of using categories to organize that content. I'm going to create an article for each "publisher" category. I'll manually add links to each publisher's newsletters in that publisher's article. I'll also create a parallel menu structure like I was describing above.
Anyway, that's a lot of background info, with the hope that I'll get some confirmation that I'm not doing something fundamentally flawed.
The problem is that there are external sites linking directly to some URLs like above. I don't want these links to break (classic SEO problem, I believe). I think the solution is to use 301 redirects to (for example) redirect from:
http://www.global-autotrading.com/autotraded-newsletters/13-angel-publishing/43-options-trading-pit.html
to
http://www.global-autotrading.com/autotraded-newsletters/angel-publishing/options-trading-pit.html
or from
http://www.global-autotrading.com/autotraded-newsletters/4-10-percent-per-month/12-10-percent-per-month.html
to
http://www.global-autotrading.com/autotraded-newsletters/10-percent-per-month.html
There are various guidelines around for creating 301 redirects in IIS (ex: http://www.webconfs.com/how-to-redirect-a-webpage.php), but I was wondering if these are compatible with Joomla, particularly with Joomla with the SEO features turned on.
Also, if it seems like I'm doing something fundamentally wrong, please let me know :)
Thanks!
Here is the rewrite section of a web.config file that works. The trickiest part was to figure out that the redirect rules need to preceed the SEO rules in the web.config
<rewrite>
<rewriteMaps>
<rewriteMap name="StaticRedirects">
<add key="/old-url-1.html" value="new-url-1.html" />
<add key="/old-url-2.html" value="new-url-2.html" />
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="Security Rule" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAny">
<add input="{QUERY_STRING}" pattern="mosConfig_[a-zA-Z_]{1,21}(=|\%3D)" ignoreCase="false" />
<add input="{QUERY_STRING}" pattern="base64_encode.*\(.*\)" ignoreCase="false" />
<add input="{QUERY_STRING}" pattern="(\<|%3C).*script.*(\>|%3E)" />
<add input="{QUERY_STRING}" pattern="GLOBALS(=|\[|\%[0-9A-Z]{0,2})" ignoreCase="false" />
<add input="{QUERY_STRING}" pattern="_REQUEST(=|\[|\%[0-9A-Z]{0,2})" ignoreCase="false" />
</conditions>
<action type="CustomResponse" url="index.php" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
<rule name="Redirect Rule" stopProcessing="false">
<match url=".*" />
<conditions>
<add input="{StaticRedirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="False" redirectType="Permanent" />
</rule>
<rule name="SEO Rule">
<match url="(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" pattern="" ignoreCase="false" />
<add input="{URL}" negate="true" pattern="^/index.php" ignoreCase="false" />
<add input="{URL}" pattern="(/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
Code similar to this was recently included in the default Joomla install starting at version 1.6.2.
It is important that all external redirects are listed before any internal rewrites, otherwise the rewritten pointer will be inadvertently exposed back on to the web as a new URL.

Resources