Normally I Deploy my websites on servers with Apache ModRewrite using a simple rule in .htaccess to redirect the address with www to without www: www.example.com => example.com
I'm currently deploying a website on a server with Windows using IIS + UrlRewrite.
In my web.config file where you realize redirection settings I have the following rule to remove the www address:
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
</conditions>
<action type="Redirect" url="http://{C:1}/{R:1}" redirectType="Permanent" />
</rule>
Via browser, redirection works perfectly!
But several external tools, such as Facebook and Google+1 button, does not work when the redirection rule is active.
For example, the Google+1 button gives an error to click it (in the requisition click the button I can see the error: "code": -32099, "message": "Backend Error").
Already with Facebook realize the problem when trying to analyze the website with the www address with the following tool: http://developers.facebook.com/tools/debug
Facebook error: URL Parsing Error: Error parsing the URL typed, no data was collected.
Disabling the redirection, the Google+1 button and Facebook's analytics tool work perfectly.
Note: the principle does not inform the site because I want to leave a disabled rule to find the solution. If it is necessary to inform the link I will edit this question.
EDIT:
After some tests, regardless of the rule enabled or not my problem with the +1 button continues.
I found a thread on Google Code about the same problem, but not understand what should be done:
http://code.google.com/p/google-plus-platform/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Component%20Owner%20Summary%20Stars&groupby=&sort=&id=241
The problem occurs only bound to the site. I created a test page with two +1 buttons, one pointing to the site and pointing to Stackoverflow. By clicking the button Stackoverflow works, but not the other:
http://renalvida.org.br/teste.php
Related
Recently I have been facing very strange issue with IIS rewrite module. So, I am trying redirect one of URL to a desired URL.
<rule name="Redirect to merchant dashboard login page" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAny">
<add input="{CACHE_URL}" pattern="*://*/*/login*" />
</conditions>
<action type="Redirect" url="https://dev.mydomain.com/apply/{C:3}/login" />
</rule>
In IIS manager this rule look like this:
also, just for the reference, in IIS manager there is option to test the pattern with my URL. So I give a screenshot of it how it look like:
As you can see, from the above picture my pattern extracting backreference correctly. So, when I hit a URL which match with this pattern I am expecting it should redirect me to the URL stated in IIS redirect URL part. However, when I hit a URL for example "https://dev.mydomain.com/rms/login" it append lots of "apply" word to the redirected URL which is so weird. Like the image below:
while debugging the issue from the browser I have found that when I hit the URL it hit the url multiple times and each time it add the backreference {c:3} to the redirected URL as a result it does not work.
What is so strange is the when I just change the rule name "Redirect to merchant dashboard login page" to "Redirect to merchant dashboard signup page" it works perfectly, which is - it redirect me to my expected URL https://circle.dev-youlend.com/apply/{C:3}/login
I am not understanding how can a change in Rule name make it working, how can I make it working even when I change the rule name?
A Temporary down page (e.g. updating your servers SW) should ideally have a response code of 503, but you could get away with 307, but in no case should it be 200 (as google will index this and it will affect your SEO)
In IIS rewrite rules, you have 3 options for implementing a redirect to a down page, rewrite, redirect and customResponse:
<action type="Rewrite" url="/site1.html" />
<action type="Redirect" url="/site1.html" redirectType="Temporary" />
<action type="CustomResponse" statusCode="503" subStatusCode="0" statusReason="Site Unavailable" statusDescription="Down for maintenance" />
The problem is if you want a 503 response, you cant redirect to the required page.
We have 3 websites for different brands using episerver CMS.
When we do maintenance, or just want to take a site down, we have a single azure web app (aka iis) which has 3 holding pages, one for each.
so our site down website has 3 pages:
/site1.html
/site2.html
/site3.html
We use Azure traffic manager to point to the live site or the site down page, and we currently have redirects which work, but incorrectly give 200 response:
<rewrite>
<rules>
<rule name="site1" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="mysite" />
</conditions>
<action type="Rewrite" url="/site1.html" />
</rule>
<rule name="site2" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="myothersite" />
</conditions>
<action type="Rewrite" url="/site2.html" />
</rule>
etc.
</rules>
</rewrite>
In order to fix this issue (offer a different site down page per site, and respond with 503), what are the options?
I would guess its possible to setup something like 3 different named virtual hosts, each with nothing except a custom 503 error page + a catch all CustomResponse action? Any examples of such a config?
To be clear, our app may well be running normally, but we may want to use our traffic manager to point the public at a "down" page which has a 503 respose during maintenance. The website sorving the down page has nothing to do with the website serving the site/applicaion itself.
Sadly, as the Microsoft document describes – there is no way to customize the 503 HTTP error.
Even use rewrite to make it display custom 503 page, In fact the request get into IIS and rewrite successful, then response to client. The whole process is perfect and your web service doesn’t stop.
The error is detected by the IIS server as it attempts to hand the incoming request to application. Everything application does is performed in its app pool. Modules like rewrite and custom error page are all executed in this way. 503 handled by the http.sys you cannot create a custom error page at all, as it is processed before it gets to iis. Therefore, both hope that the web server will stop reporting 503, but also hope that the server can process the request to display the page you defined. These two conflicts.
If your application is asp.net, there’s another way to custom 503. You can place a text file named "app_offline.htm" in the root of the site, all requests to that website will redirect to that app_offline.htm file. Basically, if you need to take an entire ASP.NET site offline, you can place some nice message in that file. Then, any new requests to a URL, any URL, in that website will redirect to that file allowing you to do maintenance to the site, upgrades, or whatever. It is not really a redirect though. ASP.NET essentially shuts down the site, unloads it from the server, and stops processing any requests to that site. That is, until you delete the app_offline.htm file - then things will continue as normal and your ASP.NET site will load up and start serving requests again.
We are migrating our old site to a new one (wordpress hosted on Azure) but for some reasons we need to maintain the old one one online. Suppose the site are:
new site www.site.com
old site www.oldsite.com
This is what we need:
if a user enter www.site.com/somepath and this doesn't exist, it must be redirected to www.oldsite.com/somepath.
Is it possible by setting url rewrites in web.config or by redirecting 404 error to the old domain?
Thank you in advance,
Marco
From your information, I'd assume you are using WordPress template (not WordPress on Linux) from Azure Marketplace (in which during the WordPress web provisioning, you are asked to chose whether Azure MySQL or MySQL in App option). You can download IIS Manager extension and remotely connect to your site then start writing your rule. You can also download the web.config file (via FTP and make it up yourself). Here is the reference of web.config https://social.technet.microsoft.com/wiki/contents/articles/32229.azure-create-an-url-rewrite-azure-web-app.aspx
The below is sample rule
<rewrite>
<outboundRules>
<rule name="404redirection">
<match filterByTags="None" serverVariable="{RESPONSE_STATUS}" pattern="^404" />
<conditions>
<add input="{HTTP_HOST}" type="Pattern" pattern="^http://newwebsite.net/somepath(.*)">
</conditions>
<action type="Redirect" value="http://oldwebsite.net/somepath(.*)" />
</rule>
</outboundRules>
</rewrite>
Note that this is the sample rule based on the web server variable with HTTP response (404). If you WordPress uses some custom query strings or so on, the rule is supposed to be more complicated than this one.
I need to redirect a "fake" sub domain to a real subdomain in IIS 7.5. The reason is that the marketing department doesn't want to use the actual website address in print pieces.
Actual site URL:
reporting.usapartners.com
Marketing dept wants
report.usapartners.com (fake) to redirect to reporting.usapartners.com (real)
Again, report.usapartners.com does not exist, only reporting.usapartners.com exists
Here is what I tried
I added a binding in IIS, for the site reporting.usapartners.com. I added report.usapartners.com as the host name and used the reporting.usapartners.com IP address
Then I went into reporting.usapartners.com web.config and added this:
<rewrite>
<rules>
<rule name="report" stopProcessing="true">
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="report.usapartners.com" negate="false" />
</conditions>
<action type="Redirect" url="http://reporting.usapartners.com" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Looks like my solution creates an alias that cannot be redirected to.
Am I even approaching this problem correctly? Seems like it should be a simple problem to solve but perhaps not? Any ideas are welcomed and appreciated.
Thanks
I think you need to create a separate site with host bindings for report.usapartners.com (the fake site) in IIS. This is going to be a stub site (it will still need a path on the disk, but it's only going to have a web.config in there) which will just host a redirect rule.
Now click on HTTP Redirect for that site in IIS and tick Redirect requests to this destination and put http://reporting.usapartners.com in the textbox. Then tick Redirect all requests to exact destination (instead of relative to destination), don’t tick the next one and then choose Status Code Permanent (301).
If you want it to redirect and keep the subdirectories and/or query string, then you can change the contents of the textbox to be http://reporting.usapartners.com$S$Q. Note that there is no trailing slash in this case. The $S preserves the sub directories and the $Q preserves the query string.
Your rule is causing a redirect loop.
Observe what your rule does:
Match any given URL (this includes "/", "/something", "/something/another.html", etc.)
If the host name ISN'T "report.usapartners.com"
Redirect permanently the request to "http://reporting.usapartners.com"
So, as you see, as soon as the user is redirected to the reporting subdomain, it gets redirected again to reporting, because hostname isn't "report.usapartners.com".
The key here is the negate="true" attribute on the rule condition. Remove it or set it to false and you are good to go.
Edit:
You are almost there.
The real solution would be to change the host name on the rule to the desired host, keeping the negate true, so your rule would do:
Match any given URL (this includes "/", "/something", "/something/another.html", etc.)
If the host name ISN'T "reporting.usapartners.com"
Redirect permanently the request to "http://reporting.usapartners.com"
Code:
...
<add input="{HTTP_HOST}" pattern="reporting.usapartners.com" negate="true" />
...
For my IIS website, I'd like to redirect ALL requests to ONE page. The purpose of this is that I want to do some maintenance on the database (take it off-line) that all my web applications use. I have about 50 web apps running under this website, so I'd like to avoid visiting each of them to change something. I'm thinking I could make a single change in machine.config? Any hints would be appreciated.
If you are using ASP.NET 2.0 (or higher), you can drop an app_offline.htm page on the root.
More info here.
in webconfig
<rewrite>
<rules>
<rule name="redirect all requests" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
Make all the pages un-available, probably stop the current web site and create an entire new completly blank site in its place. Then put up a custom error page for the 404 (file ot found) error. Custom Errors is a tab on the properties dialog of the web site in IIS. Just create the page you want to send, then change the entry for 404 on the custom errors tab to point to the new file you just created.
In IIS 10 there is an optional component "HTTP Redirect" (it may be available in earlier IIS versions; I don't know).
It allows you to set up very simple catch-all redirects, using any of the common HTTP redirect response codes.
This can be installed via Server Manager, in Windows Server 2019.
Could you create a new site in IIS with a binding to port 80 with a blank host-header (much like the Default site) and then stop the other site(s)? That way all requests would be handled by the new site, which could simply be a static HTML page notifying users that the site is down for maintenance.