I am trying to get a URL rewrite so it takes a URL for e.g my.site.com and rewrites it to "Http://localhost:8080". I keep getting default homepage instead of it being redirected. I have configured the rewrite as follows :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="mysite">
<match url="(my.+)" />
<action type="Rewrite" url="http://localhost:8080" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I am at a loss, is there something I am doing wrong ???
Any help will be greatly appreciated.
Cheers
Jeff
It is not 100% clear what you want to achieve and why, but because localhost is involved, it seems you do not want to rewrite but maybe perform a http redirect. Rewriting means that your request URL is sort of changed into another one, like index_foo.htm could be rewritten to index.aspx?what=foo.
But you want to change the domains, so you need to redirect. Try:
<system.webServer>
<httpRedirect enabled="true" destination="http://localhost:8080" childOnly="false" />
</system.webServer>
This will keep whatever local page you have called, i. e. my.site.com/foo.htm will be redirected to localhost:8080/foo.htm.
Because this looks like a temporary thing for development purposes, you can add
httpResponseStatus="Temporary"
to httpRedirect (may be important in order not to lose search engine rankings).
Related
Long time listeners, first time callers.
We are trying to accept old inbound links, that are currently bouncing.
The old urls contain: /County_Detail.cfm/CountyID:XXX (XXX = UniqueID)
We want the old links to redirect to /Counties/County_Detail.cfm?CountyID=XXX
We're using CF10 and IIS 8.5
We simply want to replace the delimiters / and :
We've tried a number of settings, with the following as the latest:
<rewrite>
<rules>
<rule name="Rewrite Counties" stopProcessing="true">
<match url="^County_Detail.cfm([a-zA-Z0-9-+]+)CountyID([a-zA-Z0-9-+]+)" />
<action type="Redirect" url="County_Detail.cfm{R:1}CountyID{R:2}" />
</rule>
</rules>
</rewrite>
Would someone kindly point out the error of our ways.
Thank you, so much!
I have two projects on my server on running at same ip.
a.company.com (MVC)
b.company.com (WEBAPI)
I want to redirect;
a.company.com/api/(.*) => **b.company.com/(.*)
Like that, but i want to keep b.company.com hostname is hidden. Its mean i want to rewrite it, not redirect.
Thanks.
You will need to have the URL Rewrite module 2.0 loaded, which is available via the platform installer. this will allow you to do server-side URL rewriting.
I can't say exactly what your rules should be but if you do it at the site level you will get somthing like this in your web.config in the system.webServer section:
<rewrite>
<rules>
<rule name="rewrite" patternSyntax="Wildcard">
<match url="/api/*" />
<action type="Rewrite" url="/{R:1}" />
</rule>
</rules>
</rewrite>
You will need to use the correct capture groups to match your situation.
I want to redirect index.php to home in this snippet.
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect index.php to home" stopProcessing="true">
<match url="index.php" ignoreCase="false" />
<action type="Redirect" url="home" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
I have IIS Express 8.5 running. No redirect is happening for http://localhost/index.php, I get index.php and the same old 404. Tried deleting browser cache, didn't help. Any idea?
I don't have to do anything to enable the Url-Rewrite-Module, do I?
Ok I finally found the problem. My ASP.NET MVC 5 project had two Web.configs:
/Web.config
/Views/Web.config
I had put the snippet above in /Views/Web.config by mistake, and it didn't work. Now I moved it to /Web.config, and it works perfectly.
I have created a website on Azure, and linked it with custom domain name(CNET).
Now, when I look at domains on website configuration on Azure panel I see both www.mywebsite.com , and default mywebsite.azurewebsites.net. Both of these domains work fine and I can access website using any of these.
How can I remove mywebsite.azurewebsites.net domain? Does having both of these domains affect SEO?
EDIT*
Thanks for answers, I am trying to enable a 301 redirect, but it is not working. I have added this to web.config file ("example" being my actual site name)
<system.webServer>
<rewrite>
<rules>
<rule name="SEOAzureRewrite" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.azurewebsites.net$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
I run the website but nothing happens. I can still access the mysite.azurewebsites.net address.
there is no problem in having both domains pointing to your website.
for SEO, you must do 301 redirect from mywebsite.azurewebsites.net to www.mywebsite.com.
It has to be 301 redirect. As this will tell the search engines to always index www.mywebsite.com
Since I couldn't set up the url rewrite in web.config, I created global filter to check for azure url and display error if so. Here is the filter, and I added a new view in my error pages for this purpose that just says "Page doesn't exist" to avoid indexing by search engines. Think this will solve possible duplicate indexing issues.
public override void OnResultExecuting(ResultExecutingContext context)
{
if (context.RequestContext.HttpContext.Request.Url != null)
{
string path = context.RequestContext.HttpContext.Request.Url.AbsoluteUri;
if (path.ToLower().Contains("mywebsite.azurewebsites") && !path.ToLower().Contains("error/oldazuresubdomainredirect650"))
{
throw new HttpException(650, "Azure legacy");
}
}
}
You can create a url rewrite rule to do exactly that
You just need to add a redirect rule to your site’s web.config file. You can do that by adding the following rewrite rule to the web.config file in your wwwroot folder. If you don’t have a web.config file, then you can create one and just paste the text below into it, just change the host names to match your site’s host names:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect rquests to default azure websites domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^yoursite\.azurewebsites\.net$" />
</conditions>
<action type="Redirect" url="http://www.yoursite.com/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The above is all you need to do to get it to work. If you'd like to better understand what exactly that code does and why it works, there's a detailed writeup at https://zainrizvi.io/blog/block-default-azure-websites-domain/
Is there a setting to force the language in the URL? Like, if I browse to http://www.site.com, I should be redirected to http://www.site.com/en, as it is now I can see the start page without the language prefix.
The LinkManager is configured to always put in the prefix so all the links look fine at least.
Another way to use is our SEO Friendly URL Module.
This module implements a custom LinkProvider that provides SEO Friendly URL's and forces items to be accessed through their friendly URL.
So if an item is accessed without the language code in the URL (e.g. /my-item) the module will 301 redirect to the URL with language code (e.g. /en/my-item).
That is, if you have configured it to force friendly URL's (forceFriendlyUrl="true") and set languageEmbedding="always".
We use that module on our corporate website, so take a look at that to see it in action.
You can use ISS URL Rewrite to redirect / to /en
Install that module on the IIS, and setup a rule.
It can be done from the IIS gui or from web.config
I am using this rule to do the same.
Insert the following configuration in the system.webServer section in web.config
<system.webServer>
<rewrite>
<rule name="redirert / to en" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{PATH_INFO}" pattern="^/$" />
</conditions>
<action type="Redirect" url="/en/" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
It will redirect every request hitten "/" to "/en"