IIS Rewrite Not Working - asp.net

I'm trying to get URL rewriting working but having problems. I have several rules set up with BlogEngine.NET and I want to redirect several pages to a "Coming Soon" page. Despite being able to access a valid page at mydomain.com/page/coming-soon.aspx by typing it directly, if I try to access it via mydomain.com/category.aspx, the rule below does not work - I just get a 404 that '/page/coming-soon.aspx' does not exist.
<rule name="Coming Soon4" stopProcessing="true">
<match url="^category.aspx/?$" />
<action type="Rewrite" url="page/Coming-Soon.aspx" />
</rule>

Don't you mean to have type="Redirect" instead of Rewrite?

Related

Can you change your primary Wordpress URL without breaking the old url?

When I installed Wordpress I decided on what I thought would be a decent URL and started writing blog posts and pointing people to www.moreGenericDomain.com/myblog/. Everything worked, and still works, fine. But as my blog focus was narrowed the domain didn't quite suit it anymore.
I've since purchased a new domain that I would like to use. When I go into settings and set www.NewDomain.com as the blog address everything works fine for that domain. Further, the urls are cleaner as they have changed from www.moreGenericDomain.com/myblog/post-1 to www.NewDomain.com/post-1. So everything seemed to go going great.
However, after this change www.moreGenericDomain.com/myblog/post-1 would give a Wordpress 404 page. This is very undesirable as I already have a number of links to my blog posts and a few initial subscribers. I don't want to lose this established traffic that I've worked so hard for.
Is it possible to switch to the new domain name while keeping the old one functional? In other words, I would like www.moreGenericDomain.com/myblog/post-1 to redirect to www.NewDomain.com/post-1.
Update
Per some helpful tips in the comments I tried setting up rewrite rules. My web.config looks like this:
<rewrite>
<rules>
<rule name="multAccounts">
<match url="http://oldDomain.com/LMBlog/post-1/" />
<action type="Rewrite" url="http://newDomain.com/post-1/" />
</rule>
<rule name="darkEssences">
<match url="http://oldDomain.com/LMBlog/post-2/" />
<action type="Rewrite" url="http://newDomain.com/post-2/" />
</rule>
<rule name="GuildBash">
<match url="http://oldDomain.com/LMBlog/post-3/" />
<action type="Rewrite" url="http://newDomain.com/post-3/" />
</rule>
<rule name="KvK">
<match url="http://oldDomain.com/LMBlog/post-4/" />
<action type="Rewrite" url="http://newDomain.com/post-4/" />
</rule>
</rules>
</rewrite>
The first rule seems to work correctly, while IIS ignores the other 3. I've used IIS' rule editor to test my input URL and it says it matches, but when I go to that URL I am not redirected and Wordpress gives me a 404.
I also tried a regex rule:
<rules>
<rule name="RegexRewrite">
<match url="([a-zA-Z\-\:\/]+)oldDomain.com\/lmblog\/([a-zA-Z\-]+)" />
<action type="Rewrite" url="http://NewDomain.com/{R:2}" />
</rule>
</rules>
However, that is completely ignored; no rewrites occur at all and I received the Wordpress 404 page. I suspect that Wordpress is preventing IIS from doing url rewrites.

Redirecting wordpress urls in a ghost site hosted in Azure

I recently switched my blog from wordpress to ghost. In order to keep the old wordpress urls working, I added some rewrite rules.
My wordpress site used the following url formats:
/blog/year/month/post-title
/blog/index.php/year/month/post-title
Ghost uses the following url format:
/post-title
Here's my main rewrite rule. It works fine for the pattern without index.php, but with index.php, it redirects to /index/.
<rule name="wordpress to ghost" stopProcessing="true">
<match url="^blog/(index\.php/)?\d+/\d+/([\w\-]+)/?" />
<action type="Redirect" url="{R:2}" />
</rule>
How can I fix this rule to correctly redirect urls with index.php?
I've tested this with my own installed instance of Ghost on Azure, but I'm not getting the redirect you are. {R:2} correctly returns the second grouping (slug name).
However, I do notice that you are not escaping your forward slashes. Try the following:
<rule name="wordpress to ghost" stopProcessing="true">
<match url="^blog\/(index\.php\/)?\d+\/\d+\/([\w\-]+)\/?" />
<action type="Redirect" url="{R:2}" redirectType="Permanent" />
</rule>

replace underscore with dash using url rewrite module of iis

I have issue regarding Url rewrite module.
I want to implement permanent redirect (301) into my site. and url is, I want to permanently redirect
http://demo.datadiary.com/search/product/ahmedabad/ac_dealers
url to
http://demo.datadiary.com/search/product/ahmedabad/ac-dealers
Thanks in advance.
I got the solution. put the following into your web.config, but keep in mind that your host must have installed Url rewrite module in iis.
<rule name="Imported Rule 1-2" stopProcessing="true">
<match url="(search/product/ahmedabad.*/[^/]*?)_([^/_]*)$" ignoreCase="false" />
<action type="Redirect" url="{R:1}-{R:2}" redirectType="Permanent" />
</rule>

iis7 redirect from exact url to new site

I want to re-direct from an exact URL request to a new site within that domain.
I need to re-direct requests from
www.example.com/site111/default.aspx?configX.xml
(this site uses a different config file to load content)
to
www.example.com/site222/default.aspx
Issue is that I need to leave access www.example.com.au/site111/default.aspx
so I cannot just to a http re-direct as there is no file called default.aspx?configX.xml
I think I need to use a URL rewrite re-direct
Can someone help me with the syntax for the web config I cannot get it to work
0 module installed and have used the above syntax and it still doesn't work,
If I use the test feature on the module it says that the string matches,
very confused,
the actual webconfig section is here
<rewrite>
<rules>
<rule name="Redirect2" stopProcessing="true">
<match url="\/nrmmaps\/default.aspx\?config=nrmproject.xml$" />
<action type="Redirect" url="/nrmproject/default.aspx" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
and the old link is
http://se.nrmspace.com.au/nrmmaps/default.aspx?config=nrmproject.xml
and I want it to re-direct to
http://se.nrmspace.com.au/nrmproject/default.aspx
Do you have any idea why this is not working?
I believe you need to install the IIS rewrite module which can be found here:
http://www.iis.net/downloads/microsoft/url-rewrite
After you do that, you can add a rewrite section with a redirect rule in your web.config like so:
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url="\/site111\/default.aspx\?configX.xml$" />
<action type="Redirect" url="/site222/default.aspx" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>
Hope this helps

Use IIS7 URL Rewriting to redirect all requests

I have a .NET site that I am taking down and I plan on redirecting all requests to www.mysite.com using a rewrite rule in the web.config. Should be a simple task, but it's not. I've removed all the content from the filesystem except a single Default.aspx page and a default web.config with the following rewrite rule:
<rule name="Redirect All" stopProcessing="true">
<match url="^(www\.)?mysite\.com(/.+)$" />
<action type="Redirect" url="www.mysite.com" appendQueryString="false" />
</rule>
If I request www.mysite.com/garbage.aspx the server is still trying to look up garbage.aspx, or any other url I provide just as if the rewrite rule was not there.
Very frustrating. Ideas?
Do you want to redirect ALL requests to your new site? If so, this should do it:
<match url=".*" />

Resources