How do I negate login.aspx in the web.config with Wordpress - asp.net

We have recently created a Wordpress site which will be hosted on a Windows 2012 Server. The server is currently serving compiled code of which one of the URL's it uses is login.aspx.
When we add the Wordpress site and enable permalinks, we get the default Wordpress page instead of login.aspx.
We have unsurprisingly narrowed it down to the web.config rewrite rule.
<rewrite>
<rules>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule>
</rules>
</rewrite>
I'm sure we have to negate the login.aspx page some how but I'm not sure how to do it. This has to work as a single site for now.

All I needed to do was add in the following:
<add input="{URL}" negate="true" pattern="*.aspx" />

Related

How to redirect Wordpress blog through IIS in combination with existing ASP.NET site

I started installing (through the Web Installer Platform) a Wordpress blog on my Windows (2012) Server.
On this server I'm already hosting a ASP.NET MVC 4.5 site.
Now, before I can proceed configuring the Wordpress site (by opening www.***.com/wp-config.php),
I seem to create a new redirect rule in IIS / web.config.
Otherwise it will give conflicts with the existing ASP.NET site.
I have tried this redirect rule:
<rule name="wordpress blog" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
<add input="{REQUEST_URI}" pattern="^/(blog)" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule>
With this rule, when opening https://www.****.com/blog/wp-config.php I end up with a runtime error on https://www.****.com/blog/error?aspxerrorpath=/blog/wp-config.php
And when adding in www.***.com/wp-config.php (so in the root folder)
<rule name="block" stopProcessing="true">
<match url="^blog$" />
<action type="none" />
</rule>
and going to https://www.***.com/blog/wp-config.php, I am getting the same errorpage as above.
I can't seem to figure out how this rule should look like. Is there anyone who can help me out there?
According to your description, I suggest you could try to use belwo url rewrite rule in the asp.net application.
This rule will redirect all the request with blob to the index.php.
<rule name="wordpress blog" >
<match url="blog/(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="http://{yourdomian}/blog/index.php"/>
</rule>
It was solved by adding "blog" in the global.asax.cs in the ExclusionFilter as follows:
i18n.UrlLocalizer.QuickUrlExclusionFilter = new System.Text.RegularExpressions.Regex(#"(?:sitemap.xml|.css|.jpg|.png|.svg|.woff|.woff2|.eot|.js|.html|.json)$|(?:blog)");

Redirect Non-WWW to WWW (except one spesific subdomain)

On my Windows 2012 server I have installed the URL Rewrite module in IIS. I have followed this guide to redirect non-www to www in web.config:
http://www.surfingsuccess.com/asp/iis-url-rewrite.html#.VF6GBid0yAU
So far, so good!
The only problem is that we also host the subdomain "api.example.com". This API stops working when I apply the code in web.config.
My question is: What is wrong with the code below? Why does the subdomain stop working when I try to redirect non-www to www, except "api.example.com"?
<rewrite>
<rules>
<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" />
<add input="{HTTP_HOST}" pattern="^api\.example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>
</rules>
</rewrite>
I have similar check and I have same rule but have specified differently in pattern.
My suggestion is to enable Failed request tracing to check URL rewrites.
http://www.iis.net/learn/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules
Edit: Updated rule.
<rewrite>
<rules>
<rule name="non-root" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(www.example.com)$" negate="true" />
<add input="{HTTP_HOST}" pattern="^(api.example.com)$" negate="true" />
<add input="{HTTP_HOST}" pattern="^(example.com)$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>
</rules>
</rewrite>
Actually, there was nothing wrong with my rewrite code. The reason why the API stopped working was because it had a referance to the top domain of the site (example.com), this caused a conflict with the rewrite code. After changing the referance to the www -version of the doman (www.example.com) everything worked fine.

URL Rewrite Map and Wordpress

I am working on a migration from ASP.NET to Wordpress and I want to put 301 redirect rules in place using a Rewrite Map with URL Rewrite in IIS 7.5. I have all the redirects in a file named rewritemap.config, and I've created the redirect rule in URL Rewrite in IIS, but I can't get the redirect to work with Wordpress. I don't know if this is possible with Wordpress having it's own rewrite rule in the web.config as well to send everything to index.php where it handles it's own rewrites internally as explained in this link:
How does Wordpress rewrite the URL without a rewrite map?
The XML for the web.config is below:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rewriteMaps configSource="rewritemap.config" />
<rules>
<rule name="Redirect old links from redirect map" stopProcessing="true">
<match url=".*" negate="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
<rule name="wordpress" enabled="true" patternSyntax="Wildcard">
<match url="*" />
<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="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The XML for the rewritemap.config file was created by IIS Admin so I expect that it is correct and it matches the format I've seen on other blog posts that have shown how to do this. Am I attempting something impossible with this? I have hundreds of old aspx pages I need to 301 redirect to specific links in the Wordpress site and there are to many external references to the old links to even think about not having the 301 redirects in place.

IIS7 URL Rewrite for short urls

I've been working on a small link length supressor site and can't seem to figure it out on IIS7. I'm used to working on isapi rewrite and mod_rewrite.
The following scenario is active:
Lets say I have test.com, thats the main domain. The domain should process all files normally. But when the /.* isn't a directory nor a file, it should send it to redirect.asp?text=(.*).
This is what my web.config looks like
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="YOURLS 1" stopProcessing="true">
<match url="^([0-9A-Za-z-]+)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="redirect.asp?test={R:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
Can't see much wrong with your rule, except maybe that you use test (with an 's') as the query string parameter in your web.config but in your text you say that it should be text. A typo or maybe that's the reason it's not working?
<action type="Rewrite" url="redirect.asp?text={R:1}" appendQueryString="false" />
It seemed to have to do with a wrong version of the URL rewriter. I installed the latest 2.0 and it was fixed!

URL rewrite - web.config error

I am getting the following error when i run my .aspx page.
Error Code0x8007000d
The configuration section 'rewrite' cannot be read because it is missing a section declaration
I have a simple v.aspx page which has the following code:
Response.Write(Request("q"))
My hosting server as IIS 7 installed with URL rewrite feature enabled (that's what they claim)
My web.config file has the following lines under :
Note: The node has blue squiggly lines under it
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="v.aspx?q={R:1}" />
</rule>
</rules>
</rewrite>
I have searched stackoverflow but did not find a solution.
May be someone found a solution.
TIA
Make sure your <rewrite> is enclosed in the <system.webServer></system.webServer> section.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="v.aspx?q={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Install the URL Rewrite module http://www.iis.net/download/URLRewrite and that should be sorted. It fixed my problem
The rewrite section in system.webServer is supported in IIS7, but not IIS6. The error is likely caused by deploying this site to a server that's only running IIS6.

Resources