I am trying to redirect all non existent pages to a different domain, as my blog was moved to a different domain.
So www.mydomain.com/blog/asdf should redirect to blog.mydomain.com/blog/asdf
Using Intelligencia URLRewriter module I can redirect blog/ but if I do blog/something I get a 404.
Even with a simple rule without regex like this one, it doesn't work for anything under the blog folder
<rewrite url="~/blog/^" to="http://blog.softwaresynergy.com/blog/" />
I also tried this to force all requests to go to the handler
<modules runAllManagedModulesForAllRequests="true">
Any ideas on how to pick up everything under blog/ and redirect to the other domain?
Try with following redirect rule:
<redirect url="^/blog/(.+)$" to="http://blog.softwaresynergy.com/blog/$1" />
put it at the top of your other rewrite rules, so it gets executed first, I think it should work.
URL Rewriting does not allow to rewrite path on other domain or subdomain. You can redirect the url by using this code in global.asax:
void Application_BeginRequest(object sender, EventArgs e)
{
string path = Request.Path;
if (path.Contains("blog/"))
{
HttpContext.Current.Response.Redirect("http://blog.softwaresynergy.com/blog/");
}
}
Use a custom 404 page.
<system.webServer>
<httpErrors existingResponse="Replace" errorMode="Custom">
<remove statusCode="404"/>
<error statusCode="404" path="/Custom404.aspx" responseMode="Redirect" />
<customErrors mode="On">
<error statusCode="404" redirect="/custom404.aspx" />
Inside the custom404 page I'd put code to do my redirect. Getting the path that caused the error would probably be a combination of...
Request.QueryString("aspxerrorpath");
Request.UrlReferrer;
Once I have the path they were trying to access just do a redirect.
Response.Redirect(NEW_SITE + PATH, true);
I did the change in a different way. Left the original site as php and did the redirect using php rewrite which works fine.
In the domain new.mydomain I did the aspx site
Not ideal, but worked for now.
Related
In Asp.net Mvc 5 How we can redirect another page if controller name is invalid in url like http://localhost:51056/free
Redirecting to a controller name that doesn't exist will always return an HTTP 404 (Not Found) response.
Probably the best way would be to set up a redirection rule on your server that redirects /free to some other path that does exist.
You can set configuration in web.config like
<customErrors mode="On" >
<error statusCode="404" redirect="/404.shtml" />
</customErrors>
or You can do this in Global.asax
if (Context.Response.StatusCode == 404) {
// handle this
}
We are trying to rewrite like domainname.com/cityname. However this not resolving to the respective page. But when we try something like this domainname.com/city/cityname it works well and resolve to the correct/designated url
This is the code in webconfig
<rewriter>
<rewrite url="~/city/(.+)" to="~/Default.aspx?propid=$1" processing="stop"/>
</rewriter>
How to redirect to the page by giving domainname.com/cityname
Thanks in advance
try
<rewriter>
<rewrite url="/(.+)" to="/Default.aspx?propid=$1" processing="stop"/>
</rewriter>
where $1 is the fraction after / in the url
so
something.com/name_of_city
will redirect to
something.com/Default.aspx?propid=name_of_city
In my production environment, I would like to redirect all requests to /trace.axd to return HTTP 404. Currently, the default HTTP 500 is returning. This creates all sorts of unnecessary noise in our analytics tools. Environment is ASP.NET 4.0 web forms on IIS 7.5.
Remove the tracing HTTP handler in the Web.config file:
<system.webServer>
<!-- remove TraceHandler-Integrated - Remove the tracing handlers so that navigating to /trace.axd gives us a
404 Not Found instead of 500 Internal Server Error. -->
<handlers>
<remove name="TraceHandler-Integrated" />
<remove name="TraceHandler-Integrated-4.0" />
</handlers>
</system.webServer>
Navigating to /trace.axd now gives us a 404 Not Found instead of 500 Internal Server Error.
First that comes to my mind is to intercept BeginRequest event in global.asax:
protected void Application_BeginRequest()
{
// assuming that in your production environment debugging is off
if (!HttpContext.Current.IsDebuggingEnabled && Request.RawUrl.Contains("trace.axd"))
{
HttpContext.Current.Response.StatusCode = 404;
HttpContext.Current.Response.End();
// or alternatively throw HttpException like this:
// throw new HttpException(404, "");
}
}
I want to convert my 404 status code in to 301. I have top indexed site in SEO and I don't want to loos my position if bot don't found my page.
For some URLs I am getting 404 status and by redirecting to some another page with 404 status code is not good thing for SEO.
So I want to convert status code to 301 so it wont affect my indexing.
I want to set 301 status code when it gives 404. My site is in asp.net 1.1 and I have tried lot of solution before.
Some solutions are giving me 301 instead of 404 status code but they gives in second step. Means first they are giving 302 then they are giving 301. But I don't want to do that. I want directly from 404 to 301.
Is it possible with asp.net 1.1 and IIS?
Please help me in this.
Thanks
You can configure error redirects using your application's web.config. Here's an example:
<customErrors mode="On" defaultRedirect="~/somecatchallpage.aspx?type=error">
<error statusCode="404" redirect="somecatchallpage.aspx?type=404"/>
<error statusCode="301" redirect="somecatchallpage.aspx?type=301"/>
</customErrors>
Here's some additional reading (for asp.net version 1.1): customErrors Element
Did you try it with the global.asax?
void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
if (exception is HttpException)
{
Response.Redirect(..);
}
}
I have:
<!-- Force lowercase URLS -->
<rewrite url="~/(.*[A-Z]+.*)$" to="~/handlers/permredirect.ashx?URL=${lower($1)}" />
Perm redirect simply 301 redirects to the new URL.
This rule is meant to redirect any URL with an uppercase char to the lower case one.
This however creates a redirect loop, any ideas why? The only rules running so far are:
<rewriter>
<!-- Remove Trailing Slash for all URLS-->
<rewrite url="~/(.*)/($|\?(.*))" to="~/handlers/permredirect.ashx?URL=${lower($1)}$2" />
<!-- Force lowercase-->
<rewrite url="~/(.*[A-Z]+.*)$" to="~/handlers/permredirect.ashx?URL=${lower($1)}" />
<rewrite url="~/construct2($|\?(.*))" to="~/construct2.aspx" processing="stop" />
</rewriter>
You can either modify the regular expression to exclude .ashx files (which might get extremely complicated) or create a new rule before this rule, that will catch URLs pointing to ashx files and redirect them to a lowercase version of the string.
Something like this might work (not tested):
<rewrite url="~/(?=(.*\.ashx.*))(.*[A-Z]+.*)" to="~/${lower($1)}" />
It uses a lookahead rule to check if ".ashx" is part of the url and if the URL is uppercase. If yes, it redirects to the lowercase version of the same url.